Feature Request, Cannot Reset Global Variable Tick Box

Discussion and feedback on Construct 2

Post » Sun Nov 30, 2014 2:44 pm

@Ashley

Hey Ashley, could you add a tick box "Cannot Reset" next to the "Static" and "Constant" tick boxes?
Some games use global variables to store if the player is dead or not, but need to reset everything else when the player dies.

Currently it's set up so that you have to make a function to reset every global variable except for the one you don't want reset.
The moderators are corrupt and ban for no reason, especially that condescending neckbeard asshole Kyatric. The forums are filled with fanboys.
Banned User
B
22
S
7
G
1
Posts: 558
Reputation: 2,925

Post » Sun Nov 30, 2014 8:16 pm

@Nesteris

What about using webstorage to store those values?

https://www.scirra.com/manual/120/webstorage
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Sun Nov 30, 2014 10:45 pm

@TiAm
However if the user opts to clear all their cookies or offline website data, WebStorage will be cleared.

I don't know, it'd be pretty silly if the user cleared their WebStorage and found that they broke the game.

Using global variables the way I set it up now is perfect, if the player dies he can respawn, if I exit game completely and open it up again the player doesn't double spawn. (If the global variable has the value "Dead", then upon New Game, a new player is created. So value got saved between closing and opening the game again, it would break.)

Could I set it up the same way using WebStorage or Dictionary Key? Using Session Storage with WebStorage seems promising, but I wish I didn't have to change it.

Could I use a Dictionary Key / WebStorage to get the same functionality I have with Global Variables ?
The moderators are corrupt and ban for no reason, especially that condescending neckbeard asshole Kyatric. The forums are filled with fanboys.
Banned User
B
22
S
7
G
1
Posts: 558
Reputation: 2,925

Post » Mon Dec 01, 2014 12:59 am

Nesteris wrote:@TiAm
However if the user opts to clear all their cookies or offline website data, WebStorage will be cleared.

I don't know, it'd be pretty silly if the user cleared their WebStorage and found that they broke the game.


The player is highly unlikely to clear webstorage in the middle of playing your game. The advantage of webstorage is persistance between play sessions, good for high scores, level progress, that sort of thing.

However, it seems like the variables you are talking about would only be relevant during runtime. In that case, your best bet would be a global dictionary; it's contents won't be cleared when clearing global variables.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Mon Dec 01, 2014 1:10 am

However, it seems like the variables you are talking about would only be relevant during runtime. In that case, your best bet would be a global dictionary; it's contents won't be cleared when clearing global variables.


Meaning that they reset to "default" when you exit the application/.exe?
I can use keys in the same way I use Global Variables, right? I can change the value for a key and set up the conditions as if I was using global variables, could I get confirmation of that?

Thanks a lot for the help, this past month development has been booming so fast I can barely keep up and I'm the developer! :lol:
The moderators are corrupt and ban for no reason, especially that condescending neckbeard asshole Kyatric. The forums are filled with fanboys.
Banned User
B
22
S
7
G
1
Posts: 558
Reputation: 2,925

Post » Mon Dec 01, 2014 2:52 am

Nesteris wrote:
However, it seems like the variables you are talking about would only be relevant during runtime. In that case, your best bet would be a global dictionary; it's contents won't be cleared when clearing global variables.


Meaning that they reset to "default" when you exit the application/.exe?
I can use keys in the same way I use Global Variables, right? I can change the value for a key and set up the conditions as if I was using global variables, could I get confirmation of that?


Yes. You still have to initialize the dictionary, which you can do in a subgroup/function/etc. Here's an example capx:
You do not have the required permissions to view the files attached to this post.
Don't lose your work. Backup your game with Dropbox.
B
44
S
10
G
10
Posts: 1,106
Reputation: 9,202

Post » Mon Dec 01, 2014 4:21 am

Do I really have to go through all those events that include Global Variables to replicate the usage of a single global variable?

Since we're using Global Dictionary, I can't just make a key "PlayerStatus" with a value "Alive", and set it to "Dead" when the player is destroyed so the game knows to create a new player when the new game layout starts? I think you might be making it needlessly complicated.

Could I set it up like this? It seems a lot simpler this way.
test.capx
You do not have the required permissions to view the files attached to this post.
The moderators are corrupt and ban for no reason, especially that condescending neckbeard asshole Kyatric. The forums are filled with fanboys.
Banned User
B
22
S
7
G
1
Posts: 558
Reputation: 2,925

Post » Mon Dec 01, 2014 2:14 pm

I got the same result by using a Global Dictionary with a Boolean Instance Variable, thanks for the help @TiAm !
The moderators are corrupt and ban for no reason, especially that condescending neckbeard asshole Kyatric. The forums are filled with fanboys.
Banned User
B
22
S
7
G
1
Posts: 558
Reputation: 2,925


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 6 guests