How do I get enemies to change direction when hitting walls?

Just started using Construct 2? Post your questions here

Post » Thu Feb 11, 2016 6:04 am

If it were to reset every tick it would still affect other instances, but it doesn't. It only affects whatever is in the scope of the variable. Outside of the scope, the variable is moot. In another scope, when another object collides the variable is initialized again as we're outside the scope of the last event. (Any ''condition'' that has a little green arrow by it is also an event, they are triggered by the system, rather than constantly being checked for. So they're a bit more efficient than looking through all your conditions every tick when there's no need to do so.)
B
5
S
1
Posts: 43
Reputation: 461

Post » Thu Feb 11, 2016 3:31 pm

So you mean it only resets if the event is triggered?
B
7
S
2
Posts: 56
Reputation: 583

Post » Thu Feb 11, 2016 3:44 pm

It resets as soon as we leave the sub-event we've placed it in. (Or rather, it doesn't reset at all. But the variable is only valid in that specific sub-event and its children, any new sub-event of the sort will create a brand new variable. What we see in the UI does not equate to what happens on the internals of a programming/scripting language. The unused ones will eventually be picked up by the garbage collector and cleaned up as they're no longer in use.)

The beauty of a scope, anything inside of it is valid while you're in the scope. Any time said scope is encountered the values start out completely unaware of the last time the code was run. (Unless specifically stated otherwise, but if we start including that now things will get really confusing.)

If you're interested, there's some decent information regarding scopes and the reach of variables around the web. One such example would be this: http://people.cs.clemson.edu/~turner/co ... ch8_5.html
B
5
S
1
Posts: 43
Reputation: 461

Post » Thu Feb 11, 2016 4:08 pm

Its interesting so a local variable is created and destroyed every time the event runs instead of being simply
reset to its starting value?
So it will take up no memory while the programm is running other events?
Makes kinda sense for optimization reasons i think.
B
7
S
2
Posts: 56
Reputation: 583

Previous

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 5 guests