0 Favourites

Problems setting an instance variable

  • On shift pressed

    For each Object

       Object is overlapping Object2

          If Object variable = "Follow"

            Set Object variable = "Stay"

          If Object variable = "Stay"

            Set Object variable = "Follow"

    Why is this not working for me? It seems to set the varaible to "Follow" regardless of the previous value. :/

  • You have to remember the code is executed from top to bottom.

    In your case, when the var = "Follow", it is set to "Stay".

    And right after, it testes if the var = "Stay" (which is true since we just changed it) and so it sets it to "Follow", but the testes are done and the code executes for another object.

    By the way, you don't need the "For each object" in the top level event, this is implicit in C2, the conditions are tested for all instances of the object, and the sub-events will use the picked instances from the first event.

    What you would need here is rather :

    On shift Pressed

    Object is overlapping Object2

    ..Local variable Temp = 0

    ..If Object variable = "Follow"

    ..If Temp = 0

    ..==>Set Temp to 1

    ..==>Set Object variable to "Stay"

    ..If Object variable = "Stay"

    ..If Temp = 0

    ..==>Set Temp to 1

    ..==>Set Object variable to "Follow"

    Like in this capx.

    You can see the actions are only applied to the instances picked in the top level event.

    When you check for overlaping, it only picks the instances overlaping.

    That's how events work.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Yea. I can see now what was going wrong.

    That's the way I suspected I would have to do it.

    Is there no way to break out of an event? instead of using temporary variables like this? :/

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)