Saving Layouts?

For questions about using Classic.

Post » Sun Jan 24, 2016 10:51 am

Trying to think about ways I can optimize things and survive in the horrible hellscape which is 'being trapped in a CC project'. Figured if I could export levels and load them I would be able to get rid of that whole 'bloated EXE with 20 copies of the same code' issue. Fortunately if I can't deal with that, with the amount of content left to do, I'll be left with an EXE, load time and ram usage that is embarrassing, but acceptable. But I'd like to fix that.

So the biggest issue with saving anything that I'm having is variables. So plugins like S seem to be good at sucking down a bunch of stuff and saving it, but S doesn't account for object variables from what I tell? Which would make it totally unusable. Then that would lead to the situation where I would have to manually export and load all the variables on everything and that would be an absurdly unacceptable amount of work. So is this at all possible? Would I need to write a plugin to make it manageable? Could it be done in a python script?

One gross method I played with a little bit but doesn't seem stable or safe is using save states. I could get some stuff working but it seemed far too gross and broken to fully consider, but maybe? Current method involved renaming the layout to be saved as what would be the 'loader' layout and then saving it and switching the layout back. It works pretty okay in test caps but getting it to work in a full game is something I haven't tried to do yet because I remember hearing some weird things about saving and loading being a bit wonky and also this being a real hack.

So any thoughts or ideas or other hacks, here? Whatever idea has to be a pretty robust solution. If there is an edgecase there is a decent chance I'd hit it.
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Post » Sun Jan 24, 2016 11:50 pm

You probably could use python to do it. The Sprite.NumVars expression gives the number of private variables and then you can do something like this to loop over all the variables.

for i in range(Sprite[0].NumVars):
Sprite.Value(i)

The trick here is you can access a value by it's index instead of by it's name.

I don't have time to make a full solution but you can access everything you need from python. Next you'd need to come up with a way to save and load that data to and from the disk. It's not hard just takes a bit of thought.
B
89
S
30
G
95
Posts: 5,160
Reputation: 63,456

Post » Mon Jan 25, 2016 9:04 am

Excellent, good to know! And I have a few people I can probably bug to try and help me with this if I have any problems. Hopefully if this ends in a clean solution, I might end up with something to share, but who knows.
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Post » Sat Feb 06, 2016 4:29 am

My "I Had Hope" game loaded all the levels from simple INI format files, but I didn't write a level editor/layout to INI saver for it (might have an example of that in my Examples Kit download in the signature too though).

Source code to IHH alpha is up at http://ihadhope.blogspot.ca/p/download.html
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
109
S
38
G
17
Posts: 2,172
Reputation: 18,989

Post » Sun Feb 07, 2016 7:46 am

I wonder about the ini thing simply because the scope is so big, level wise. Like upward of 6000 objects. I could do python to capture the variables (... can you use python on the currently 'picked' object? Somehow I doubt my life will be that simple but who knows.... evaluated python command maybe? Is there any even vaguely decent python docs on how its integrated?)

But hey I guess I can give this a try without the variables and just see it it can hand;e things with a reasonable load time.
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Post » Sun Feb 07, 2016 8:37 am

Heeeey 9 seconds to load a level (excluding a lot of details and important variables and whatever). That's.... not good enough. And I'd say I'm on an optimal system (reading off an SSD and stuff).I'm guessing the ini plugin is the bottleneck here but who knows. I might be asking the impossible out of poor construct.

Bloated EX issues add like 20 seconds or something to the booting of the game, but that seems preferable to slow loads every death. Maybe if I do all the object attributes in single strings I can cut down on reads and speed things up. Gonna try that next.

I think this direction might be boned though because I realize there isn't a way to detect collision settings, which I use very very very frequently. =/
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Post » Sun Feb 07, 2016 8:49 am

You can access the picked objects using the SOL object.

So say the object name is "sprite", then in Python you would loop over the picked sprites with:

for obj in SOL.sprite:
obj.x=2


There are some older posts with more details about Python that may also help. Anything accessible with events is accessible from Python, well except many conditions such as triggers can't be used in Python but that's about it.

Give me a day or so and I'll wip up an example.
B
89
S
30
G
95
Posts: 5,160
Reputation: 63,456

Post » Sun Feb 07, 2016 9:07 am

Awesome, thanks everyone. Interested to see what you have in mind, r0j0 :D

So my 'objects as huge string' experiment was massively successful. Load time is like a second or two. Gotta figure out selection too for handling things like width and height. Creating objects by name/oid doesn't seem to do selection, sadly? But I'm sure there is a way to do most recent object or something?

Image

Anyways, works at a reasonable speed. Also sad that there is no expression for visibility either. That is a pain. (Though I guess I can work around that one fairly easily) I could wrestle some edgecases if I have to though.

I suppose I could do something goofy and set tiles that are non-colliding as like opacity 99 or something. It'd be a pain to track all that shit down but I definitely could.
Last edited by kayin on Sun Feb 07, 2016 9:15 am, edited 1 time in total.
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Post » Sun Feb 07, 2016 9:15 am

Hmm, sounds like what is effectively a JSON storage format if it's all one big string, I think in that case you might find the HashTable or Binary object even faster for saving and loading it all at once (Binary object saves to encrypted file too which should make cheating harder!).

I've not tried them for this though, but the process shouldn't be too large of a code difference from your current system (HashTable might be the most event-friendly approach).

HashTable usage: example-tips-hashtable-object_t69861

Edit: Also this works for me for getting the most recently created object UID after it's created by name then applying some code to it in the next tick: https://dl.dropboxusercontent.com/u/471 ... DCheck.cap

Getting that to work with the loop you have might be a matter of doing sub-events to check what the object being created is though, so depending on all the types of objects that might be a lot of code.
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
109
S
38
G
17
Posts: 2,172
Reputation: 18,989

Post » Sun Feb 07, 2016 9:57 am

Hashtable load speeds = immediate. AWESOME. This is getting quite reasonable.

Doing a few things shouldn't be too bad. I'm pretty sure sprites and tiled backgrounds are the only two object types that need to be saved.

edit: Yeaaah I can see that being a problem now. Especially the 'next tick' part (spending 6000 ticks generating a level is no go).

I'm trying to do a thing where I make another set of hash keys with like oid : x : y with all the other parameters to try and identify things and run through that list the next frame, but for whatever reason that has problems too (size mismatches on random objects and such. Enough headbanging for tonight. Especially curious if python could help with any of this. Anyways, thanks for all the help.
B
12
S
4
G
4
Posts: 238
Reputation: 2,426

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests