Is this a bug? Can't pick objects created in the same tick

0 favourites
  • 9 posts
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.
  • Hi everyone. I just wanted to make sure this was a bug (and not a known one) before I reported it. It seems pretty fundamental and like it would have been reported by now, but I couldn't find it with any of the search terms I tried.

    Basically, if you create an object you cannot perform any actions on it outside the event that created it (and it's subevents) until the next tick.

    This capx is a simple example.

    After creating the box the action to set it's scale to half size works since it's in the same event.

    The next 'every tick' takes place immediately afterward and sets the size back to normal and changes the angle, but it applies to every box except the one created in that tick.

    If you toggle on the 'Wait 0 seconds' action, it works as expected since it is no longer the same tick as the creation.

  • I'm not sure, but i think this has something to do with the order Construct uses to perform actions each tick.

    I think Construct creates objects at the final part of a tick. So the scaling action will be runing earlier then the creating action.

  • lucid

    I think this is expected behavior.

    I usually have my creation methods wrapped in a custom function called "Spawn (ObjectName, X, Y)" which returns the UID of the new object. If you explicitly pick by UID after the creation, then this problem shouldn't happen.

    It's best to just have a master Creation function to handle spawning of all objects. Having it also lets you "spawn by name" so you can easily switch Enemy.Projectile = "HomingMissile" or Enemy.Projectile = "RegularBullet", assuming these are Object Type names. Keeps your code clean.

    EDIT: Screenshot

  • lucid

    you might try shift right the event 3.

    The SOL would affect remain actions and sub-events. But it would not affect remain events in the same level or higher.

  • Thanks for the responses everyone. I had never run into this before now.

    The situation was basically

    On Function "create everything"
        --loop
              --create several objects and set their initial private variables according to an algorithm
        --every tick 
              --call function "update everything" 
    
    On Function "update everything"  (used outside the "create everything" function as well)
        --several conditions here checking objects' private variables
              --perform actions on each object based on some algorithm involving each object's private variables[/code:gyfvteju]
    
    So using the 'wait 0 seconds' before the "update everything" in the first function was the cleanest workaround.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yeah, after creation, outside of the same event or sub-events you have to wait till the next toplevel event to be able to pick the new object.

    More details I've compiled in the past. CC did it too.

  • Thanks R0J0hound, that was very useful.

    I didn't realize that you could still affect the newly created objects from other top-level events, or that the function triggers didn't count as top-level events. Good to know.

  • [quote:2q8zl984]Thanks for the responses everyone. I had never run into this before now.

    Think its a problem everyone runs into at one point or another

    However I would suggest that you design your game to not use wait 0. It can cause problems.

    In your case you could just move the actions from the second "every tick" to the first one and it would work without wait 0.

    A rule of thumb is as Rojo pointed out as well. When you create an object, you have to initialize it in the same event, or a sub event to where it was created.

    All in same event
    Top level: Create object
                       Set object color (Works)
                       -----> Sub level
                                 Set object size (Works)
    
    Top level: Set object position (Wont work)
    [/code:2q8zl984]
    
    [quote:2q8zl984]function triggers didn't count as top-level events.
    
    Just saw this  They will work, you just have to make them in the sub level or same level as the create, as shown in the code example.
  • Check to:

    • -call function "update everything"
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)