How do I save specific global variables?

Just started using Construct 2? Post your questions here

Post » Sun Dec 06, 2015 3:26 am

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?
B
47
S
14
G
4
Posts: 177
Reputation: 5,389

Post » Sun Dec 06, 2015 12:17 pm

Local storage?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Dec 07, 2015 12:33 pm

@Callan_S
Yes. Through local storage.
Getting high score would look something like this:
Image
B
7
S
2
Posts: 68
Reputation: 645

Post » Tue Dec 08, 2015 12:50 am

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?
B
47
S
14
G
4
Posts: 177
Reputation: 5,389

Post » Tue Dec 08, 2015 3:20 pm

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..

Callan S wrote: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 told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Dec 08, 2015 11:06 pm

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'.
B
47
S
14
G
4
Posts: 177
Reputation: 5,389

Post » Tue Feb 02, 2016 3:38 pm

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:

Image

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

Thanks!
B
7
S
2
Posts: 14
Reputation: 548

Post » Tue Feb 02, 2016 4:06 pm

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.
ImageImageImage
B
71
S
19
G
181
Posts: 3,484
Reputation: 103,689

Post » Tue Feb 02, 2016 4:41 pm

blackhornet wrote: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.
B
7
S
2
Posts: 14
Reputation: 548

Post » Tue Feb 02, 2016 4:51 pm

Yep that sorted it quite perfectly. Didn't realise how directly I was comparing the values at the time. Thanks again for your help!
B
7
S
2
Posts: 14
Reputation: 548


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests