Webstorage

Discussion and feedback on Construct 2

Post » Tue May 08, 2012 1:03 am

I want to create a game that keeps track of your money. I want the value of the money to be the same throughout the life of the game, not just for one play... I've been told that webstorage is where I should go, but how do I set variables in webstorage? I also want to know how to acquire the data that has been storwed and display it. Kind of like a shop. Can someone upload a .capx with everything in webstorage, or educate me as to how I would accomplish this? Much obliged.
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Tue May 08, 2012 1:48 am

Here is a capx. You click the button to rack up a score and store it. Click it a few times, close the program, then reopen it and the score should take up where you left off before. This should work even in the C2 preview. Read the manual for more.

http://dl.dropbox.com/u/6109058/webstorage_test.capx
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

Post » Tue May 08, 2012 1:54 am

Thanks @jimand but can I add local keys other than numbers, like variables?
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Tue May 08, 2012 2:17 am

With Webstorage, you save key / value pairs. The values can be numbers or text.

In my example the local storage key was "StoredScore" and the value was a number. You can do the same thing with text. You could have a key "Item" and a value of "lamp" or "table" or whatever.

http://www.scirra.com/manual/120/webstorage
B
16
S
4
G
1
Posts: 40
Reputation: 2,705

Post » Tue May 08, 2012 2:31 am

Numbers, text...
Arrays if you are clever...
Sprites if you're REALLY clever (base64 strings or something I think)
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue May 08, 2012 2:57 am

@sqiddster can you show me an example of web storage from your game airscape?SearingSky2012-05-08 02:58:11
B
20
S
4
G
4
Posts: 129
Reputation: 5,535

Post » Tue May 08, 2012 11:14 am

I use webstorage just to remember what level the player is up to. All you need is the action "set local value" and then the webstorage expression "webstorage.localvalue()".
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Tue May 08, 2012 11:49 am

@SearingSky: Have a look at the "How do I FAQ" section "Webstorage", I guess you'll have the answer you're looking for.
Save variables/example of use

Remember a variable can be put about anywhere in an expression field, just don't use quotes.
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 » Mon May 14, 2012 8:12 pm

Can I store images in Arrays - using key-value pairs? Should I use WebStorage?
B
19
S
6
G
4
Posts: 7
Reputation: 4,231

Post » Mon May 14, 2012 8:13 pm

I don't see why you would need to store an image, since there is no way to create images at runtime anyway...sqiddster2012-05-14 20:13:21
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Next

Return to Construct 2 General

Who is online

Users browsing this forum: spacedoubt, Unconnected and 1 guest