Save a variable so it keeps its value even on exit

Get help using Construct 2

Post » Fri May 17, 2013 7:48 am

Hello!

I want to buy Construct 2, but I first want to make sure that it is equipped with this feature.

Basically, lets say that my game has a 'Highscore' global variable and a 'Level' global variable. I want to save both of those variables so, even if the user quits my application and restarts their device (this will probably be either a NodeWebkit desktop application or an Android app), my variables will be remembered and reloaded when they reopen the application.

Is this possible, and if so, how? Please explain in a newb-friendly way.

Thanks!

OrangeFlash81
B
8
S
2
G
2
Posts: 47
Reputation: 1,890

Post » Fri May 17, 2013 8:25 am

@orangeflash81

Firstly, welcome to the forum!

Construct2 can save both number variables and text strings (eg, names on a scoreboard) using a plugin called 'web storage'. You can find out more in this Manual entry here: https://www.scirra.com/manual/120/webstorage

It's ridiculously easy to use (I've just started using it in my current project and was surprised to discover I only needed to add the object and click a few buttons) and saves data via cookies. scirra have recently added an even better saving feature which allows you to add a proper save game system to projects, though I've yet to experiment with it.
B
12
S
3
G
1
Posts: 235
Reputation: 2,053

Post » Fri May 17, 2013 12:53 pm

@Dave Hailwood, what about completely offline saving? does webstorage or the new save game system work for that?
B
32
S
4
G
1
Posts: 266
Reputation: 2,426

Post » Fri May 17, 2013 4:03 pm

[QUOTE=damjancd] @Dave Hailwood, what about completely offline saving? does webstorage or the new save game system work for that?[/QUOTE]

Yeah, that was what I had in mind. Thanks for your suggestion though Dave. I might end up using that. Would that still work on Android, though?

Thanks!
B
8
S
2
G
2
Posts: 47
Reputation: 1,890

Post » Fri May 17, 2013 4:18 pm

@damjancd
@OrangeFlash81

Webstorage is the browser storage, if the cache isn't deleted, it should stay (even on node-Webkit)

And for the Node Webkit plugin, you can save a file with data in a folder on the user computer, and also load a file, so, it works offline

(the node-webkit plugin is still in beta though, so you may take that in consideration)

Hope that helps
https://www.scirra.com/forum/viewtopic.php?t=152506

And that is why you shall respect the bug reports guidelines, not only giving a capx is making the bug reproductible in one click in a situation they can work with (less time wasted trying to reproduce vague instructions) but also it helps filtering false positives.

Game design is all about decomposing the core of your game so it becomes simple instructions.
B
42
S
17
G
16
Posts: 2,094
Reputation: 15,355

Post » Fri May 17, 2013 7:23 pm

@Aphrodite Thanks for the reply, I'm particularly interested in iOS completely offline data saves. So webstorage doesn't work for me since I need a reliable method to save a game. I'm aiming for a Appstore release a week or two after they release ios 7 (hopefully with webGL enabled) :]
B
32
S
4
G
1
Posts: 266
Reputation: 2,426

Post » Fri May 17, 2013 7:27 pm

WebStorage works offline, works on all platforms, and is permanent. It is *not* saved in the browser cache; it's permanent and immune to the user clearing their cache. (I don't know why everyone assumes it saves to the cache!)

There's also good support for full-state savegames and the node-webkit plugin allows writing to disk when a desktop application.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,580

Post » Sat May 18, 2013 8:35 am

[QUOTE=Ashley] WebStorage works offline, works on all platforms, and is permanent. It is *not* saved in the browser cache; it's permanent and immune to the user clearing their cache. (I don't know why everyone assumes it saves to the cache!)

There's also good support for https://www.scirra.com/tutorials/526/how-to-make-savegames and the node-webkit plugin allows writing to disk when a desktop application.[/QUOTE]

Thanks! Problem, though; I can't find the WebStorage object anywhere. I am on Construct 2 Free Edition Release 119. I am looking to buy Standard.

P.S. With Standard, can I sell games that I create? Or is that only for Business releases?
B
8
S
2
G
2
Posts: 47
Reputation: 1,890

Post » Sat May 18, 2013 8:38 am

you should first update your version to 126 or the 130 Beta

Webstorage is an Object, just add it to your project yonda2013-05-18 08:39:43
B
18
S
6
G
3
Posts: 197
Reputation: 4,129

Post » Sat May 18, 2013 3:04 pm

[QUOTE=OrangeFlash81] [QUOTE=Ashley] WebStorage works offline, works on all platforms, and is permanent. It is *not* saved in the browser cache; it's permanent and immune to the user clearing their cache. (I don't know why everyone assumes it saves to the cache!)

There's also good support for https://www.scirra.com/tutorials/526/how-to-make-savegames and the node-webkit plugin allows writing to disk when a desktop application.[/QUOTE]

Thanks! Problem, though; I can't find the WebStorage object anywhere. I am on Construct 2 Free Edition Release 119. I am looking to buy Standard.

P.S. With Standard, can I sell games that I create? Or is that only for Business releases?[/QUOTE]

Right-click on your layout and add object, then select web storage. Now it will be available throughout your project. And yes, you can sell games with a standard license. If you exceed a certain threshold of revenue, you need to upgrade to business.
B
90
S
32
G
14
Posts: 935
Reputation: 14,540

Next

Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], DiabloOvermind, emoticon, odiusfly and 20 guests