How do I pick Array within a Container inside a Function

0 favourites
  • 4 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.
  • I have a Sprite object and an Array object.

    The Array object belongs to the container of the Sprite object.

    Within the event sheet, I create the Sprite object and Push several values onto the Array.

    I check the Array UID and Width and they show correctly.

    I then Call a Function, passing the UID of the Sprite as the parameter.

    Within the Function, I pick the Object instance by the passed parameter.

    At this point, checking the Array returns the original empty pre-container Array, despite the Sprite object container of the Array being picked.

    Is there something I am missing about the behaviour of Containers and object picking?

    Attached is a .capx example.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Put a 'System: Wait 0 seconds' after the Create Object so the object exists when the function is called.

    You can disregard the first printout of the array's UID. I put a battleAttackerArray:Destroy as the very first line, so there are no instances, and it still reports UID 1. edit: a 'wait 0' after the destroy fixed that.

  • Put a 'System: Wait 0 seconds' after the Create Object so the object exists when the function is called.

    You can disregard the first printout of the array's UID. I put a battleAttackerArray:Destroy as the very first line, so there are no instances, and it still reports UID 1. edit: a 'wait 0' after the destroy fixed that.

    Thank you, that fixed the issue.

    It seems that using the battleAttackerArray:Destroy on the first line which fixed it. I can remove the 'Wait 0' after the Create BattleHolder and it still works.

    Does anyone know why the presence of the initial Array instance in the layout causes this behaviour?

  • It is a bit strange. I'd be inclined to call it a bug. There is an initial Array instance created, but no battleHolder instance (which I would've thought there should be given they have a container relationship). If you use Object Layout as first layout, and disable all events, there is 1 Array and 1 battleHolder instance as expected (of course in that layout there is a battleHolder instance placed in the editor).

    If we do a similar thing with 2 Sprite objects (so have a Sprite1 and Sprite2 in a container, place a Sprite1 on the initial layout and a Sprite2 on the other layout) we get a Sprite2 created for us due to the container relationship.

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