How do I save and load arrays

Get help using Construct 2

Post » Wed Apr 22, 2015 10:49 pm

Hi, is there a way to save a lot of arrays?

the idea is the next:

In this game the player can move objects on the floor and put them in any location.
Each time the player touches a specific object the level is stored in an array so you can load it later.
The porblem is that I want to be able to load the array not only in this session of the game, is there any way to save and load the arrays in a text file or something?
Another thing, the array size is very large almost 50x50

Thanks so much for your help!!!
B
8
S
1
Posts: 34
Reputation: 434

Post » Wed Apr 22, 2015 11:53 pm

Check the manual - https://www.scirra.com/manual/125/system-actions

Scroll down just past halfway.. Save & Load.

That's the very easy way.

The other way is to save the array as JSON, then you can load it back in. More fexibility this way.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Post » Wed Apr 22, 2015 11:54 pm

"Another thing, the array size is very large almost 50x50"

Just noticed you said that. Believe me, 50x50 isn't large at all ;)
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Post » Thu Apr 23, 2015 3:27 pm

Hi, thanks for the fast response.

As i was saying (sorry for my bad english) i want this arrays to be NOT in a local save. i want the ability to share this arrays so other players can load/download them and play the levels.

i was thinking something like ajax y json but the problem is i dont know how to upload the levels(arrays) and download them... is there any tutorials or examples you know about?
B
8
S
1
Posts: 34
Reputation: 434

Post » Thu Apr 23, 2015 4:47 pm

Yeah json is the way to go then. https://www.scirra.com/tutorials/526/ho ... -savegames

Using the JSON data directly

In both the On save complete and On load complete triggers, the system SaveStateJSON expression returns a string of all the JSON data for the savegame. Note the SaveStateJSON expression will return an empty string outside of these triggers; the triggers are your only opportunity to access the data directly.

If you have your own server, it's possible to make shared savegames by posting the JSON data to the server with the AJAX object and storing it in a server database. Alternatively some platforms like Windows 8 and Clay.io allow you to store data for the logged in user, where it's shared anywhere they log in. This is a useful for allowing users to take savegames with them wherever they go.

Once you get the JSON string back, you can load the game from it using the Load from JSON system action.


I haven't messed with json stuff too much so I can't relaly help you with saving to a server and loading back from it. I can't see it being too difficult. Search the tutorials or the forums for json and I'm pretty sure you'll find some snippets ;)
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

Post » Thu Apr 23, 2015 4:52 pm

Yes Thats exactly what i need.. but i cant find an example or a real tutorial on how to do this.... Hope someone can help!
B
8
S
1
Posts: 34
Reputation: 434


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests