basic save and load

Get help using Construct 2

Post » Mon Oct 24, 2011 6:49 am

I've read the post about using web storage to save your game, but there are no instuctions on how to use that plugin. I have a global varibale"level_progress" and I'm setting the web storage to set session value to:
key:level_progress
value:level_progress
on layout start.

I'm guessing that I'm doing it wrong. Will it work on an offine output? or does it need to be posted to a server for the plugin to work?
B
8
S
3
G
2
Posts: 107
Reputation: 2,219

Post » Mon Oct 24, 2011 3:12 pm

The key should always be the same - it's like the address it looks at to save or load variables. Try

key: "level"
value: level_progress

The way you have it now if level_progress is 5, you save the number 5 under the key 5. If you load a new game level_progress presumably starts at 0, so the plugin looks under the key 0 (which doesn't exist) and gets nothing back. So just make sure you use the same key for each value.

'Session storage' also only lasts as long as the window is open - you probably want to use 'Local storage' which persists.Ashley2011-10-24 15:13:12
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Oct 24, 2011 4:10 pm

Thanks for the response, that makes sense, but it's still not working for me. Does the output need to be on a server to save? Here is the we storage section of my event sheet:

<event-block>
            <conditions>
               <condition id="-2" name="On start of layout" type="System" />
            </conditions>
            <actions>
               <action id="0" name="Set local value" type="WebStorage">
                    <param id="0" name="Key">"save_level"</param>
                    <param id="1" name="Value">level_progress</param>
               </action>
            </actions>
        </event-block>

Not sure if that helps. I set it the way you said. Should this happen "at the start of layout"?(meaning is that causing a problem?)
B
8
S
3
G
2
Posts: 107
Reputation: 2,219

Post » Mon Oct 24, 2011 5:39 pm

No, it saves to the user's computer, not the server. But if you set level_progress on start of layout, it overwrites whatever was saved there before!

You should only save a value when the user wants to save their progress. Then, you should read (not set) the value on startup.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Mon Oct 24, 2011 11:23 pm

I still can't get it to work. I guess I need a sample file or a quick step by step. I must be the only one on this website that can't save a game, so if anyone would be so kind as to send me a sample project with a save game feature that would be wonderful.
B
8
S
3
G
2
Posts: 107
Reputation: 2,219

Post » Tue Oct 25, 2011 2:43 am

I got it to work now, thanks for all the advice. I will post a basic step by step so any other noobs out there don't have to bother you.

Global variable:level_progress

system-on end of layout-WebStorage-Set local key "save" to level_progress

system-on start of layout-system-Set level_progress to WebStorage.LocalValue("save")

this should work as an auto save for any game with levels.
B
8
S
3
G
2
Posts: 107
Reputation: 2,219


Return to How do I....?

Who is online

Users browsing this forum: Artpunk, Braus, Kagubro, Mirlas, zeneizel and 21 guests