How do I make a variable which will be the same when I load?

Get help using Construct 2

Post » Tue Apr 12, 2016 8:22 am

I need to make a variable that would be the same, even when I load a Save data.
*Insert Signature here*
B
13
S
5
Posts: 73
Reputation: 1,090

Post » Tue Apr 12, 2016 8:57 am

I'm not sure about your question

You can make global variables constant (checkbox when you create a variable) - here the variable can't be changed.

But if you use local storage you can decide what happens.
Like a condition when localStorage loaded | set variableX to 1

If you use the standard system save and load (not recommended) you still can make another action after the load - like set value of variableX

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707

Post » Tue Apr 12, 2016 2:06 pm

@UltimateArceus3 - In this situation you need the local storage to make you a backup of the value of the variable so that when you load a saved data, your variable can be updated by the backup from the local storage since local storage's aren't affected by saved data's.

Example;
You have a variable named "Health"
And a local storage key named "Health_Backup"

*System->On Load Complete
----->Get item --> Key "Health_Backup"

*LocalStorage->On Item Get->Key "Health_Backup"
------> System->Set Global Variable Value-->Variable 1 to LocalStorage.ItemValue

------"That Should do it"------
Image



The Things you can create is only limited by your imagination. If you don't have the skills then use your motivation as a natural force to exceed all expectations. Chadori RebornXD
B
55
S
17
G
90
Posts: 1,112
Reputation: 59,151

Post » Tue Apr 12, 2016 2:37 pm

fm4fanAT wrote:I'm not sure about your question

You can make global variables constant (checkbox when you create a variable) - here the variable can't be changed.

But if you use local storage you can decide what happens.
Like a condition when localStorage loaded | set variableX to 1

If you use the standard system save and load (not recommended) you still can make another action after the load - like set value of variableX


Excuse me, but since you touched the subject, why shouldn't we use the native saving scheme?
Riding the Rainbow for all the eternity
B
10
S
5
Posts: 31
Reputation: 934

Post » Tue Apr 12, 2016 10:37 pm

@cenowador
The standard save/load has a lot of limitations.
Like what happens when you make an update of your game with new stuff in it (like new variables).

When I first played with save/load - sometimes my game broke
Like sound was playing even when before it was turned off and saved in this state. So when I tried to turn off the sound it played twice.

With local storage you are in total control - so I prefer it.

  • System > On start of layout | system > load game from slot "brain"
  • System > On load failed | system > scroll to obj_Forum
B
17
S
8
G
5
Posts: 340
Reputation: 4,707


Return to How do I....?

Who is online

Users browsing this forum: lolsuperscratch, RobertMKD, tarek2 and 10 guests