Question about global and local variables?

Get help using Construct 2

Post » Wed Feb 04, 2015 3:10 am

If you create an event for a family using a global or local variable, and many different object instances from that family activate that event at the same time, do they all access just ONE same variable for all the activated events, or do they each create a separate variable instance for themselves?
B
7
Posts: 20
Reputation: 293

Post » Wed Feb 04, 2015 3:45 am

There is only one variable 'instance', a Family has no special effect on a variable. You'd need to have the variable on the Family for each member instance to have its own value. Keep in mind also that local (non-static) variables are reset every tick.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 04, 2015 6:58 am

thanks. But I have another question.
Can many events be activated at the same time? For example there are 3 collisions,A collides with B, C collides with D, E collides with F, if I time them all at exactly the same time, will they all access the Event "On collision with object" at the same time? Or will they be put in a queue and take turn processing it?
B
7
Posts: 20
Reputation: 293

Post » Wed Feb 04, 2015 7:13 am

hsm4ever wrote:thanks. But I have another question.
Can many events be activated at the same time? For example there are 3 collisions,A collides with B, C collides with D, E collides with F, if I time them all at exactly the same time, will they all access the Event "On collision with object" at the same time? Or will they be put in a queue and take turn processing it?


You will have different 'on collision' events for each object type(s), and they will run from top to bottom in the event sheet. Or if they are in a Family then you can do it in one event.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 04, 2015 7:40 am

All though the computer can run really fast, it can not do more than 1 thing at a time. If an event fires 3 times at the exact same moment, they will happen one after another, thus the instance variable can be altered each time and work fine.
B
47
S
14
G
7
Posts: 603
Reputation: 8,141

Post » Wed Feb 04, 2015 8:20 am

thanks. And another question.

Say, I use a loop, for example, a while loop.

On Monster collides with ObjectA ==> subtract Monster.Damage from ObjectA.HP
while(ObjectA.HP>0)

I have Monster1 hit ObjectA, the loop occurs. Then, I create another Monster2 and it hits ObjectA, BEFORE the first loop finishes. How will the Event be resolved now? Will the first loop finishes and the 2nd starts, or will they take turn damaging ObjectA?
B
7
Posts: 20
Reputation: 293


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 27 guests