How do I add current score to total score and save it?

0 favourites
  • 15 posts
From the Asset Store
Cue in the war drums and battle cadences with Total War Game Music Loops!
  • Hi,

    I'm using webstorage to save the total score, but whenever I switch between layouts it either reverts back to 0, or it takes in only the new score without adding in the previous total score.

    The conditions are when the player collides with a coin object, it destroys said object and adds variables for 2 local variables. 1 is the new the score which displays separately, and 1 is the what will get saved using webstorage.

    When the player is dead/destroyed, the new score gets saved, 'Set local Key 'TotalScore' to Score.Total.'

    When I switch layouts, I have a condition that states at the start of the layout to set a text object to 'WebStorage.LocalValue("TotalScore").

    Am I doing something wrong?

    Any help?

  • When setting local key 'TotalScore', set it to currentScore (the one without adding previous total score) + WebStorage.LocalValue("TotalScore"). This way you will just add the new score to the previously saved one.

  • It's still showing the current score without adding the old one.

    The current score is a global variable, is that the reason?!

  • Please? Anyone?

  • There's no way to be sure whats happening, it shouldn't be a problem with global variabels unless you reset them.

    Can you share a capx?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • caiorosisca I made a new file, just to make it simpler.

    Basically got the same problem over again.

    Also note: I am using an older version of Construct, I've not got the time to download a newer one. So I'd really appreciate if you told me what I was doing wrong rather than sending me the file with corrections that I probably wouldn't be able to open.

    Thanks

  • Can anyone help me?

    Please?

  • You have no events here to add the current score to the previous total, so it seems you want to save "Total" as actually:

    WebStorage set local key "Total" to "int(Total.Text) + int(Cash.Text)"

    Also, it doesn't seem to make a difference, but I would recommend always putting the "Go To Layout" action at the bottom of the list of actions for an event, so that it never triggers before the other actions are completed.

    Hope that helps!

  • Jayjay That sadly did not help.

    It still doesn't add up. On the next layout, it still starts back up from 0, when it should take the Total from the previous layout.

    Can you tell me in full. Maybe some of my steps are wrong.

    Thanks.

  • I had a look at your capx and without re-downloading it I remember that "Total.Text" is actually the string "SAVEDCASH" that you typed in the textbox properties. Using what Jayjay has suggested "Total.text" has to be a number and since you never actually update "Total.Text" in anyway it will always be "SAVEDCASH".

    Here's a method of what should work, not at my computer with Construct so can't double check.

    Start of layout 1 (where you tested for if webstorage existed)

    Set "Total.Text" to whatever is stored in webstorage with the key "Total" if there is no "Total" key set "Total.Text" to 0.

    Then in the layout where you added the score when you end that layout (can't remember how you did that) use Jayjays method.

    WebStorage set local key "Total" to "int(Total.Text) + int(Cash.Text)"

    Personally I would use a global/instance variables for any numbers that need to be added together rather that what is stored in a textbox but that's just me. Also I would highly recommend updating Construct to at least the new Stable, you said you were using an older version, updating would be much easier for people to help you in the future by providing small examples. I fixed the capx the other day but deleted it when you said that an example would be no good

  • Minor That also sadly did not help.

    On the very first layout it loads the total, no problem with that. But when I switch to the next layout with the count increasing(displaying points received per second), it always starts back from 0.

    I need it to take into account the number saved in the previous layout, which it is not doing.

    On a side note, I know I really need to download the newest latest release, but my net speed is really bad. I will download it soon though.

    Till then can anyone help me with this?

    Please?

  • Just from my head, so there could be some unclear stuff:

    Add a global variable TotalScore

    On start of layout 1

    if local key "Total" exists set Totalscore to int(Total)

    if local key "cash" exists add int(cash) to total score

    • set text to total score

    if local key cash does not exist

    • set text to no score

    on going to next layout save totalscore to webstorage local key "Total"

    Remember to reset global variable currentscore to 0 if you want to start over on the next layout..

  • LittleStain, I did not understand any of that, and even though I tried your method out, it did not work.

    Can someone please help?

    I really need this.

  • You aren't actually loading the integer back, only the text to display. Add (on start of layout):

    Set CurrentScore to int(WebStorage.LocalValue("Cash"))

  • blackhornet, OMG, that actually worked.

    Thank you so much.

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