Global Variables

Discussion and feedback on Construct 2

Post » Sun Oct 13, 2013 9:56 pm

Hello!

I have a question about Global Variables.... Can two different instances(Sorry, I meant object types)draw from the same global variable without each other being affected? For example, If I have one enemy with 50 points for health that draws from a G.V. on the event sheet... and I have another on the same layout(two totally different object types)can they "share" the global variable? Or would both suffer damage when only one of them took damage?
Image
B
35
S
17
G
9
Posts: 103
Reputation: 8,131

Post » Sun Oct 13, 2013 11:12 pm

Use instance variables instead of global variables.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Sun Oct 13, 2013 11:33 pm

[QUOTE=KFC] Use instance variables instead of global variables.[/QUOTE]
Global Variable is used as common variable, while instance variable makes each type or instance has it own variable so when you have like three instance of the same type, when an instance get hit, it will decrease from its own instance variable, while the others remain undamaged. Hope you find it useful.
ImageImageImageImageImage
B
56
S
15
G
5
Posts: 852
Reputation: 11,431

Post » Sun Oct 13, 2013 11:48 pm

Also, if you have several objects that need a "health" variable, create a family, add the objects to the family and create a family instance variable. Much easier to work with.
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Mon Oct 14, 2013 12:24 am

@KFC @Naji

Appreciate the reply! I see the family option is the most feasible... I guess It's time I get my license for C2 ASAP... I'm missing out on these cool feature using this free version...
Image
B
35
S
17
G
9
Posts: 103
Reputation: 8,131


Return to Construct 2 General

Who is online

Users browsing this forum: LaDestitute, lukewasthefish, thimas and 4 guests