Webstorage

Forum Home Forum Home > Construct 2 General > Construct 2 general
 Post Reply Post Reply Page  12>
Author
3,515 Rep
Post Options Post Options   Quote Kapandro Quote  Post ReplyReply Direct Link To This Post Topic: Webstorage
    Posted: 08 May 2012 at 1:03am
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.
Back to Top
2,317 Rep
Post Options Post Options   Quote jimand Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 1:48am
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
Back to Top
3,515 Rep
Post Options Post Options   Quote Kapandro Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 1:54am
Thanks @jimand but can I add local keys other than numbers, like variables?
Back to Top
2,317 Rep
Post Options Post Options   Quote jimand Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 2:17am
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
Back to Top
19,240 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 2:31am
Numbers, text...
Arrays if you are clever...
Sprites if you're REALLY clever (base64 strings or something I think)
Back to Top
3,515 Rep
Post Options Post Options   Quote Kapandro Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 2:57am
@sqiddster can you show me an example of web storage from your game airscape?

Edited by SearingSky - 08 May 2012 at 2:58am
Back to Top
19,240 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 11:14am
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()".
Back to Top

Moderator
29,640 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 08 May 2012 at 11:49am
@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.
Back to Top
1,611 Rep
Post Options Post Options   Quote eryltalbot Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2012 at 8:12pm
Can I store images in Arrays - using key-value pairs? Should I use WebStorage?
Back to Top
19,240 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 14 May 2012 at 8:13pm
I don't see why you would need to store an image, since there is no way to create images at runtime anyway...

Edited by sqiddster - 14 May 2012 at 8:13pm
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down