picking problem - instances of an object inside a family

  • [quote:2v2y01r5]In what order exactly is the event sheet in C2 executing things?

    https://www.scirra.com/manual/75/how-events-work

  • blackhornet what confuses me is that C2 breaks one rule that programming languages follow:

    1.if myVar=true:

    2. dothis()

    3. myVar=false

    4. doThat()

    in traditional programming doThat() will never execute, becase myVar was set to false on line 3 and doThat is after that.

    But in construct2 everything seems to execute to the end. DoThat will do it's thing.

    Thank you for the examples. I very much appreciate them!

  • That's not true. Provide a real example. Half the time people do this, they change myVar in doThis, and then when event 3 is hit, the condition is now true so the code executes. They should use ELSE, instead of testing the opposite condition.

  • blackhornet what confuses me is that C2 breaks one rule that programming languages follow:

    1.if myVar=true:

    2. dothis()

    3. myVar=false

    4. doThat()

    in traditional programming doThat() will never execute, becase myVar was set to false on line 3 and doThat is after that.

    But in construct2 everything seems to execute to the end. DoThat will do it's thing.

    Thank you for the examples. I very much appreciate them!

    There is only a 'if myVar = true .. doThis()' event possible when there are no objects involved in that event.

    Wich is rarely and totaly not the scope of c2.

    Read this : https://www.scirra.com/manual/75/how-events-work

    Understand that an event is much more then, and very rarely a pure 'if this/then that' situation.

    If the condition is true ... it runs its actions.

    If the condition picked objects AND if the conditon is true ... It runs its actions on the picked objects. (zero picked objects = no action that actual does something)

    If the conditon is true ... AND the action is adressed to a unreferenced object, all instances of that object are adressed.

    Sub picking conditon always start with the in the top level event previous picked objects.

    Previous picked objects will be forgotten in each top level event.

    Refering to programming languages is pointless. Got to forget and read the manual.

  • lennaert thank you. In your case the solution was to make a manual timer with a new variable

    But it still has an issue - it turns too early. It should turn when it starts walking in the other direction, not when it stops.

    Your welcome blurymind

    The turning should be easily to manipulate, it just a matter of re-positioning sub-event 8 & 9 and adding a extra check on the timeout-wait check to prevent continues flipping.

    something like this

    Also, I left the for each above it, while it is not needed in most cases, it clarifies a lot (readability) when you look at it from a programmers perspective. (especially one relatively new to construct 2)

    Plus, you can move several events below it as sub-events and use the plus sign to open and close a range of events belonging to that loop. Ofc you could use a group too but ,meh, this was easy and for hand

    In the end it will generally not matter if you added it or not, as the construct 2 engine will generally create the same javascript result out of the event sheet in this case.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • ah I see. Thank you for explaining. It's very interesting how it handles events, even if a bit hard to get used to when you are used to gdscript or some other scripting language. At first glace it feels just like scripting too, but it does so much more under the surface.

    The hardest to me is moving away from object oriented scripting where logic is attached to objects - to here where a huge event sheet has logic where objects need to be identified and addressed specifically, otherwise the logic will spill and break them.

    I think the documentation should make a note that events will execute in cases where a programmer might expect them not to.

    lennaert this works like a charm now. Thank you for sharing an example with me.

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