Array Local Disk Saving/Loading

For developers using the Construct 2 Javascript SDK

Post » Tue Jan 03, 2012 1:20 am

Hello.

I would love to be able to save and load array files into the C2 array, You see.. the thing is! in my game I have "world generation", And I want to make it possible to save and load worlds. By saving them to the user disk drive.

I would be very very very great-full if this we're added!

Thank-you, dcrew!
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Tue Jan 03, 2012 2:10 am

Webstorage
Example of level editor (basic, WIP, with saving system) - LINK
Save variables/example of use of webstorage - LINK
Other example of use of webstorage - LINK

This is not exactly one action "Save my whole array" type of thing, but you have to consider HTML5 limitations (like no support of the mousewheel or no system file access (no writing to the harddrive, apart from webstorage)).
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jan 03, 2012 3:01 am

As far as I know though, webstorage can't be transferred, so it won't work for things like level editors. The only way I've determined to get it to work is using the CSV plugin, which turns a 2D array into a string, copying the string and pasting it into a 'load table from JSON string' action.

If it doesn't work, all " need to be doubled to "".
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432

Post » Tue Jan 03, 2012 3:04 am

For level editor, you may try sprite bank. It could be more useful if you want to record the instances of sprite.
B
97
S
22
G
178
Posts: 4,120
Reputation: 104,047

Post » Tue Jan 03, 2012 3:08 am

Although CSV can transfer into JSON string, it's inconvenience to save a general array/hash table, so I make a hash table plugin. You can try this.rexrainbow2012-01-03 03:12:14
B
97
S
22
G
178
Posts: 4,120
Reputation: 104,047

Post » Tue Jan 03, 2012 11:55 am

I see how it works. I thought the webstorage wouldn't work because there was like no save function.
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Tue Jan 03, 2012 11:56 am

But what if I want to save multiple different worlds.
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Tue Jan 03, 2012 1:09 pm

Save your world as a serialized string.
Each string is then a different key in the webstorage.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Tue Jan 03, 2012 2:04 pm

[QUOTE=Kyatric] Save your world as a serialized string.
Each string is then a different key in the webstorage.[/QUOTE]

Okay, also is the webstorage temporary? Does it ever get deleted? / Does the saved data ever get deleted?dcrew2012-01-03 14:04:41
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Tue Jan 03, 2012 4:33 pm

In the manual article:
[quote]The WebStorage object allows data to be stored in two places: Local storage and Session storage.

Local storage is permanent (until the user clears their cache). If the user comes back the next day, local storage still has the saved data.

Session storage only lasts with the current browser session. If the user comes back the next day, session storage is empty again.[/quote]
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Next

Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 4 guests