Assigning instance variables to global values

Get help using Construct 2

Post » Tue Aug 14, 2012 7:30 pm



Hi There,

I have a series of buttons that allow the user to switch between layers. I store the target layer numbers in instance variables on the buttons.

Sometimes, I also switch between layers through events.

I would like to store the layer numbers in global variables like "GAMEOVER_LAYER = 1", instead of just using the raw layers numbers all over the code.

However, I don't understand how to set my button instance variables to be equal to the global variables I've created. When i type the name of the global variable into the instance variable assignment box, when I hit enter, it resets the value to 0. Do I need to use some kind of prefix on the variable name? Is it even possible?

Thanks,
Peter
B
17
S
3
G
6
Posts: 14
Reputation: 3,850

Post » Tue Aug 14, 2012 7:51 pm

On start of layout (or something completly different) - > Set instance variable to global variable.

You can't type variable names to other variables in the editor. It most be done via events.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Tue Aug 14, 2012 7:54 pm

Peter, you can set an instance variable in an action. When you create the action, select your button object, then the Set value action. In the Value field, enter your global variable name.

You can also choose the global variable from the Object with expressions window, under the System object.

Edit: ninja'dWastrel2012-08-14 19:55:01
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Post » Thu Sep 06, 2012 9:27 pm

Thanks!
B
17
S
3
G
6
Posts: 14
Reputation: 3,850


Return to How do I....?

Who is online

Users browsing this forum: jeffige, Mallets and 28 guests