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

Get help using Construct 2

Post » Tue Jul 08, 2014 1:31 pm

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?
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Tue Jul 08, 2014 2:14 pm

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.
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Wed Jul 09, 2014 1:22 pm

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

The current score is a global variable, is that the reason?!
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Thu Jul 10, 2014 8:19 am

Please? Anyone?
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Thu Jul 10, 2014 2:12 pm

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?
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Fri Jul 11, 2014 5:57 am

@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
You do not have the required permissions to view the files attached to this post.
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Sun Jul 13, 2014 12:03 pm

Can anyone help me?
Please?
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Sun Jul 13, 2014 12:57 pm

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!
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit Dropbox is a pile of trash and if you need my old files PM me! :)
B
121
S
41
G
17
Posts: 2,217
Reputation: 19,696

Post » Wed Jul 16, 2014 8:01 am

@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.
B
4
S
1
G
1
Posts: 33
Reputation: 714

Post » Wed Jul 16, 2014 9:05 am

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 :(
B
46
S
23
G
7
Posts: 459
Reputation: 6,763

Next

Return to How do I....?

Who is online

Users browsing this forum: Euduardo, Kin, mikehive, ratboy3, tinhofiel and 39 guests