How do I reset global variables in ONLY ONE SHEET?

Get help using Construct 2

Post » Sun May 08, 2016 6:55 pm

Hey guys my game is about 90 % done. Core gameplay is good, I learned how to create high scores and even have separate Webstorage variables for number of this sprite destroyed, number of times this powerup was used...

I was reading the manual recently and only recently learned the concept of LOCAL VARIABLES. Having read only the parts I thought I needed, I wrongfully assumed that all global variables in one event sheet were "local to that event sheet." Now since my game is an endless wave destroyer type, most of my variables are used as Booleans for (is the game paused? Is my character currently 'dead'? Is the starting countdown over? ) and holders of information such as sprites destroyed for the current round. I tried to "localize" everything by creating a group and dragging every event and variable in there and when I pressed F5, the results were disastrous.

My current sticking point is that I'm trying to create a separate layout that holds badges and medals for achievements and those have global variables as well that compare variables such as "Number_of_Powerups_Used_When_The_Game_Was_Lauched" to "PowerUps_Used_This_Round." and as you can probably tell, using the "System: Reset Global Variables" also resets the quantity in a separate layout to 0.

I know it's my fault for not reading the manual but is there a way I could reset only my choice variables WITHOUT having to create an action for each? I think my next best option is to create a BOOLEAN that goes: "Reset_This_Event_Sheets_Variables = 1" but I don't want to have to do that if it isn't necessary.

Thank you!!
Image Image Image
B
29
S
11
G
27
Posts: 730
Reputation: 17,002

Post » Mon May 09, 2016 3:06 am

Hey Mp.

The short answer is no. Create a function called "Reset" that when called switches the global variables you need to the default setting (you could use another global variable instead of a function to trigger this but you should do yourself a favour and get used to using functions instead imo).
ImageImage
B
118
S
23
G
7
Posts: 1,070
Reputation: 12,964

Post » Tue May 10, 2016 1:35 pm

You know ive wonder how come there isnt something like a drop down style in the event or an add to list of reset global variable similar to the Family creation. That would help a bunch in controlling the game if it depend on certain variable to turn on events that is repeatable n such. And like he said to keep achievement and to reset main game global.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Sat May 14, 2016 9:56 pm

Hey guys. Late reply but thanks so much for suggesting functions.
I've since then turned a lot of my code into functions and they work like a charm.
Image Image Image
B
29
S
11
G
27
Posts: 730
Reputation: 17,002


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider], Lordshiva1948, ultrafop and 10 guests