How do I save specific global variables?

  • The load and save seem to reload the entire state of the game. Not much good if I want to give the user a bonus X points when they start the game again.

    Also for various other reasons I'd just like to save a few globals to use as the way I save and load game states. Is there a way to do this?

  • Local storage?

  • Yes. Through local storage.

    Getting high score would look something like this:

  • Thanks! I did run a search on the topic previously, but was unable to find anything at the time.

    It's a funny structure, isn't it? If the value exists, it gets it...but then it has to as if it got something to do something with it?

    Also when does this get checked? On the start of layout? Every tick?

  • First you check if something exists, if it exists you get it and when you got it you do something with it..

    First you open your drawer to see if you got socks, if you have socks in your drawer you get them, when you have them you put them on your feet..

    Very funny structure..

    Also when does this get checked? On the start of layout? Every tick?

    Looking at the events posted..

    On start of layout > check if item exists..

    I think the action to check if the item exists is called on start of layout..

  • I think it's more like 'check socks if there are in draw - if so put up a flag. If the flag is up, get the socks and...put them onto a tray. If the tray has some socks on it, put the socks on'.

    And perhaps there's sarcasm there but I'm not erudite enough to get it, but given this is a learning forum it seems easy pickings.

    In Tavi's example, 'localstr' - I assume it's just a name for ease of reading reasons. There's no reference to it in the code sample I can see.

    Left to figure it out by myself, I can only guess that 'check item highscore' then sort of 'calls' 'on item highscore exists' by passing it a value, which then triggers the rest of the set. No, this is not immediately obvious, but is still surely due some sarcasm and an extra period all the same, no doubt..

    It also seems that now the value is shown to exist, it would perpetually get it from local storage - I don't know if this is an issue, as opposed say to putting it into a global and working from that.

    I'm not sure of the point of setting the highscore text in 'on start of layout'.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I've been trying out this method for storing a High Score but whenever the game comes to an end it simply stores the score as far as the player has gone on that round. So what ends up happening is even though the current score is less than the High Score the game saves whatever the last score was.

    It's really odd because I have a check which says that only if the TotalDistance > HighScore then should it set the HighScore to the latest TotalDistance and not every time.

    Here's an example of what I'm using at the moment:

    If anyone can help me out with this I would be truly gratful!

    Thanks!

  • You are comparing apples and oranges. You check if TotalDistance is > HighScore, but then divide TotalDistance by 10, so the next time HighScore is always going to be 1/10 of TotalScore. Use a local variable to set CurrentScore = round(TotalDistance/10) then compare CurrentScore > HighScore, and save CurrentScore.

  • You are comparing apples and oranges. You check if TotalDistance is > HighScore, but then divide TotalDistance by 10, so the next time HighScore is always going to be 1/10 of TotalScore. Use a local variable to set CurrentScore = round(TotalDistance/10) then compare CurrentScore > HighScore, and save CurrentScore.

    Ah soooo, I feel like a fool. Thanks blackhornet, I'll give it a go right now.

  • Yep that sorted it quite perfectly. Didn't realise how directly I was comparing the values at the time. Thanks again for your help!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)