How do I pick a newly (dynamically) created object?

  • Hello everyone. Long time lurker, first time posting.

    I've run into an issue where, in a sub-event, I'm not able to Pick an instance that was just created in the parent event's action block.

    Code

    The code on line 2 just does not seem to want to pick the newly created S1 instance.

    Result

    (only the already-present sprite becomes 50% opaque)

    Expected

    (both sprites should be 50% opaque)

    Could this be a limitation of some sort? I've spent hours searching the manual and the forum for more info on "Create Object" and "Pick" but I haven't had any luck with anything that is related to this particular issue.

    Related .capx: bit.ly/1STJY56

    Any pointers or suggestions would be appreciated.

    Thank you.

  • It's a limitation of sorts. A forum search of "top level event" should give some topics about this.

    Basically event 1 is a top level event, and event 2 is a sub event.

    When you create and object it becomes the only picked object of that type. However it isn't added to the sprite list yet.

    I think I explain it better in another post

    Say there are 3 sprites, with uid's 1,2 and 3.

    When event 1 starts c2 internally has these three lists.

    Sprite 1,2,3

    Picked 1,2,3

    New empty

    So an object is created with uid of say 4 and at the beginning of event 2 the lists are as follows:

    Sprite 1,2,3

    Picked 4

    New 4

    Notice the new object isn't added to the sprite list yet.

    In event 2 the "pick all" condition only picks everything in the sprite list, so the result is:

    Sprite 1,2,3

    Picked 1,2,3

    New 4

    Finally after event 2 there are no more sub events of event 1 so this is a top level event and the new list is merged with the sprite list.

    Sprite 1,2,3,4

    Picked 1,2,3,4

    New empty

    Anyway there are a few ways to deal with this.

    One I've used is to just create the objects in one start of layout and effect the sprites in a second one:

    Start of layout

    --- create sprite

    Start of layout

    --- sprite: set opacity

    Another way could be to do your events as you have it but modify the new object as you create it and use pick all to affect the existing objects.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Makes absolute sense. Thanks for the quick & detailed response. I had done a lot of testing to the point where the only explanation would be that there is some sort of internal list, like you said, that only gets updated after the top level event returns. This confirms everything.

    I can see how having it work this way is more efficient but I'm left wondering if it's not entirely impossible to have a command to manually update the list (when needed), something along the lines of

    System.SpriteList.Update()[/code:3507rvg4]
    Oh well... can't have everything. 
    
    Time to hack a workaround.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)