[r100/101] can't pick object

0 favourites
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • What do you mean about code order? The trigger is fired inside the 'create object' action, the position of the trigger doesn't matter.

  • Ashley:

    Hmm, I think maybe an example would help clarify my question. My actual code is more complex than this, so I'm simplifying for purposes of this post.

    Let's say you had the following code:

    Line 1: EVENT 1

    Line 2: -- Sub Event A

    Line 3: -- -- Create Object A

    Line 4: -- -- Do some stuff

    Line 5: -- -- Create Object B

    Line 6: -- -- Do some stuff


    Line 100-105: On Created Object A Event Code

    Line 106-111: On Created Object B Event Code

    What does the actual execution order look like for this?

    Does it go:

    Line 1

    Line 2

    Line 3 (Create Object A)

    Line 100-105: (On created Object A Trigger event code)

    Line 4

    Line 5 (Create Object B)

    Line 106-111: (On created Object B Trigger event code)

    Line 6

    I read this in the manual concerning triggers:

    "Rather than running once per tick, this event simply runs (or "fires") upon something actually happening. In this case, the event runs when the user hits the Spacebar key on the keyboard. It is never checked any other time. Since triggers run upon an event happening, they aren't checked in top-to-bottom order like other events. This means the ordering of triggers relative to other events is not important (except relative to other triggers of the same type, since triggers still fire top-to-bottom)."

    The reason that I'm concerned is what would happen if Object A's OnCreated code contained a Spawn Sprite statement for SpriteC. Would SpriteC be in the SOL at the point of Line 4?


    -- countofquad

  • Well, I made a sample for another post, but it maybe can help in anything, maybe..


  • countofquad

    In regard to this Q:

    he reason that I'm concerned is what would happen if Object A's OnCreated code contained a Spawn Sprite statement for SpriteC. Would SpriteC be in the SOL at the point of Line 4?

    SpriteC would not be in the SOL. The "on created" trigger only has the newly created object picked. It does not effect the SOL of the event it was created from.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • countofquad - your outline is correct, it will trigger 'on created' during the 'create object' action and the trigger finishes before it moves on to the next action. The 'On created' event does not affect the other event's SOL at all. Events in Construct 2 pick in isolation and it is not possible for one event to change another event's picked instances.

  • Ashley, thanks for clearing that up.

    The problem with potentially using on OnCreated trigger is that I already have a OnCreated Family trigger that handles normal creation of Object A and Object B (both of which belong to this family). When one of those objects is created in a subevent, I need to set up specific variables up in Object A and Object B to certain values.

    Okay, I have an possible solution. I could create some global variables, such as:

    CreatedBy, Var1_Value, Var2_Value

    Then in code:

    Line 01 : EVENT 1

    Line 02 : -- Sub Event A

    Line 03 : -- -- CreatedBy = "SubEventA";

    Line 04 : -- -- Var1_Value = "ObjA_CustomValue1";

    Line 05 : -- -- Var2_Value = "ObjA_CustomValue2";

    Line 06 : -- -- Create Object A

    Line 07 : -- -- -- Do some stuff

    Line 08 : -- -- Var1_Value = "ObjB_CustomValue1";

    Line 09 : -- -- Var2_Value = "ObjB_CustomValue2";

    Line 10 : -- -- Create Object B

    Line 11 : -- -- -- Do some stuff

    Line 12 : -- -- CreatedBy = "";

    Line 100: On Family Created Trigger

    Line 101: -- if CreatedBy === 'SubEventA'

    Line 102: -- -- Family.Var1 == Var1_Value

    Line 103: -- -- Family.Var2 == Var2_Value

    Line 104: -- else

    Line 105: -- -- // Normal initialization for Family properties

    Does that seem like a good solution?

  • Yeah, that looks like it would work fine.

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