Keep Score between layouts

0 favourites
  • 14 posts
  • Hi

    How can I keep my global Score value going from layout to layout

    since global are reset.. on new layout

    I see that the NEW r151

    has a new feature:

    New common expression 'AsJSON' and common action 'Set from JSON'. These allow you to take advantage of the savegame system to save and load individual instance states without having to save or load the entire game, as well as other useful things like setting one object's state to another's.

    Regards

    flemming

    New r151

  • I thought global variables are only reset if you have an event to reset them?

  • Global variables aren't reset between layouts. That's entirely the point of them.

    flemmig, I can only think that you're either deliberately resetting them with an event, or you're accidentally using local variables.

    EDIT: Just saw your reply now. I'd suggest that, if you need to reset global variables often, you use WebStorage or Dictionary to store your score.

  • Yes I have alot global values I reset on each layout start

    I guess I could use a local value for the Score but its easier

    to use the global through all events -

    Or maybe somehow save to webstorage and load the Score after my

    included eventsheet in where i reset the globals

    Tried this

    <img src="https://dl.dropboxusercontent.com/u/22406377/C2-save.jpg" border="0" />

  • So actually your throwing something away that you want to keep?

  • If you have a lot of global variables already it wouldn't hurt to make one more for the global score that you don't reset.

  • Yes LittleStain

    But how is that done .. In each layout I include a Core eventsheet

    that holds the

    On start of layout > system reset global variables to default

  • Would using a global object to get the variable from one layout to the other work?

  • Hmm ..

    since it is global it is reset by system reset global variables to default

    So Im back to how to avoid it being reset, dont you think..

    If I could figure out how to save the Score value and load it after the reset..

    <img src="https://dl.dropboxusercontent.com/u/22406377/C2-save.jpg" border="0" />

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Did you read my last post?

    I'm talking about adding an instance variable to a global object or setting the value in a global array and retrieving it after resetting the global variables.

  • for the webstorage part,instead of set key in the start of layout you should do something like:

    system set value score to webstorage.localvalue("score")

  • Yes I see thanks

    Will try to get this webstorage to work

    Must be doing something wrong in that

    My global is Score

    and my textobject is txtScore

    the sprite PlayBtn > Set local key "txtScore" to Score

    ( this should save the value am I right )

    in next layout 2 I have made a button to get the score for testing

    Button Is checked > system set value score to webstorage.localvalue("Score")

  • I had this issue too. I did pretty much like you did, but instead of using webstorage, I used a dictionary. Then I created a function called resetGlobals(), in which I first copy the variables I want to keep into the dictionary, then reset the global variables, and finally copy back the values from the dictionary to the global variables. Then I just call this function whenever I need it, like when changing layout.

    Having everything in one function is easier to maintain, especially if you want to add more variables later (score, sound volume, language...)

  • Well now .. got it working!

    Forgot System Set Score to Score

    before

    WebStorage Set lokal key "Score" to Score

    Thanks 4 replies :-)

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