It’s not the condition that instantiated the variable. I believe the variable is instantiated with a value of True. Then if the conditions are not met, the variable is no longer in scope.
However, if the conditions are met, then the actions and the subevents are processed.
The first event and it’s subevents.
Remember stillLooking
is an object variable. It only exists while the event it’s declared in and it’s subevents are being processed. Once the event block is no longer processed, the local variable ceases to exist.
I’ll try to explain how it works with this coloured in image, and I’m using the example when the timer is > 1 second:
When the purple event is processed, it starts off with the variable stillLooking
being created and set to true. This variable is now in scope and GDevelop knows about it.
Next to be processed is the while event. This controls the subevents - whole orange section and is only actioned when stillLooking
is true. The first action is to change stillLooking
to false. Then a StumpChecker is placed at a random position.
The last event of the orange section checks whether StumpChecker is on an existing Stump. If it is, stillLooking
is set to true. Then While event is processed again as before.
If, however, StumpChecker is not colliding with a Stump object, then stillLooking
remains false. When the While
event is processed again, stillLooking
is false, and so the control (or prcessing) drops out of the orange section, and begins with the green section.
The orange section keeps placing a StumpChecker
until such time that it doesn’t collide with an existing stump object. stilLookning
ensures that process repeats until the StumpChecker
object is placed in a free spot.
Once the last event (the green one) has finished processing, GDevelop drops out of the purple event’s scope and processes the next event (that’s off the bottom of the screen snip). At that point the variable stillLooking
is out of scope, and it no longer exists for GDevelop. It is neither true nor false because it is no longer there. GDevelop does not know anything about it.
When GDevelop gets round to the purple event once the timer is > 1 second, the whole process starts up again and stillLooking
is instantiated again with a value of true.
I hoe this explains things.