Saving and Loading Private Variables

For questions about using Classic.

Post » Thu Nov 27, 2008 5:09 pm

Hey Guys,

First off, let me tell you guys that you have done a great job with this project. Construct is a wonderful tool to use.

I have a couple of questions. Say I have a 4 x 4 grid of simple square objects that are all instances of the same sprite. When I click on one, it changes a private variable in that instance. How would I go about saving these variable changes using a 4 x 4 array and then load it the next time the layout is started?

Also, is there any limit in the number of arrays you can have in a single layout/game?
B
1
G
4
Posts: 2
Reputation: 1,029

Post » Thu Nov 27, 2008 5:52 pm

There's no limit on the number of arrays or objects, unless you run out of memory (which is fairly unlikely).

You could try the system object's save and load or quicksave and quickload actions. They'll save the entire game state, including all private variables. Alternatively you could try an object like INI and save the ones you need to disk.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Fri Nov 28, 2008 1:51 am

Thanks for the quick response! I was just curious. In MMF I was able to spread a number into one of the object's variables to give them unique ID's. Then I used fastloops and the mod function to record the variables of each instance to an array and then load them at a later time, but that method isn't possible in Construct.
B
1
G
4
Posts: 2
Reputation: 1,029

Post » Fri Nov 28, 2008 2:15 am

You can just use 'for each object' instead to save stuff :D
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Fri Nov 28, 2008 2:35 am

Yeah, the spread values stuff is basically a long way of doing for-each (a system condition). You might be interested in for-each-ordered too, where you can change the order in which the objects are looped. A single 'for each' condition is basically the same as the 'On loop "i" / pick object whose value A = loopindex("i") event, without the spread values/variables/separate event cruft.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests