Saving and Loading an Array to WebStorage [CAPX]

Show us your completed creations made in Construct 2

Post » Sun Apr 08, 2012 2:44 pm

I couldn't find an example anywhere on the forums that demonstrated how to save and load an entire Array to/from WebStorage without plugins, so figured I'd upload one.

It's fairly well commented so hopefully it's fairly easy to understand, let me know though!

This is probably pretty useful if you want to generate and then save a random map for example, or just saving level scores, times etc.

HTML - Here
CAPX - Here

Hope somebody finds it helpful! =)

Also, this example is only for 2D Arrays, but you could easily add another loop in for 3D if you wanted =)Haematite2012-04-08 14:48:06
B
22
S
6
G
10
Posts: 118
Reputation: 8,005

Post » Sun Apr 08, 2012 10:42 pm

Im not sure what are array designed for? i know you told it's special for random map... but i would like to know what else for array?

anyways, thanks for sharing!
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,646

Post » Sun Apr 08, 2012 11:12 pm

@ Joannesalfa. An array is a data type that is meant to describe a collection of elements values/variables, each selected by one or more indices/keys.
Think an array like your classroom and you as an element in your classroom. If I want to identify you I will call you by name or go to where you sit.

@ Haematite Great stuff and made me wonder if is it possible to create a Sudoku solver by using your demonstration
B
13
S
4
G
3
Posts: 53
Reputation: 3,356

Post » Sun Apr 08, 2012 11:23 pm

[QUOTE=ZaksCommunicates] @ Joannesalfa. An array is a data type that is meant to describe a collection of elements values/variables, each selected by one or more indices/keys.
Think an array like your classroom and you as an element in your classroom. If I want to identify you I will call you by name or go to where you sit.
[/QUOTE]

Gotcha, can use array for RPG inventory?
B
96
S
25
G
20
Posts: 3,055
Reputation: 22,646

Post » Mon Apr 09, 2012 1:57 pm

@ZaksCommunicates Thanks, and yeah, should totally be possible to make a Sudoku Solver in Contruct2, maybe I'll have a go if I've got some spare time.

@Joannesalfa Yep, would be ideal for storing an inventory type thing!
B
22
S
6
G
10
Posts: 118
Reputation: 8,005

Post » Wed Apr 25, 2012 1:46 am

Thanks, this is nice stuff.
Did you find any cons yet or is this 100% good to use?

I hope someday we'll have a native save/load feature in C2.
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Wed Apr 25, 2012 3:39 am

I missed this one, thanks for sharing Haematite. Im sure it will be helpful for me in the future.
ImageImage
B
74
S
17
G
6
Posts: 1,039
Reputation: 10,605

Post » Wed Apr 25, 2012 11:19 am

Thanks guys =)

@Xavier seem to be perfect to me, it's the method I use to save data on each level in my game 'Fred' and haven't encountered any problems yet!
B
22
S
6
G
10
Posts: 118
Reputation: 8,005

Post » Mon May 14, 2012 8:51 pm

Can I store images in an Array?
B
19
S
6
G
4
Posts: 7
Reputation: 4,231

Post » Tue May 15, 2012 9:24 am

@eryltalbot, an array wouldn't store images by default but I'm fairly sure you could use Pode's Extract Sprite to base64 string plugin to get a sprite image into a base64 string format which you could then store in any array.

There are quite a few other plugins in the plugin list that can work with base64 images as well.
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Next

Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 6 guests