How do I pick Array within a Container inside a Function

Get help using Construct 2

Post » Tue Feb 17, 2015 6:54 am

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.
You do not have the required permissions to view the files attached to this post.
B
4
G
1
Posts: 6
Reputation: 335

Post » Tue Feb 17, 2015 8:26 am

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.
You do not have the required permissions to view the files attached to this post.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 18, 2015 5:54 am

codah wrote: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?
B
4
G
1
Posts: 6
Reputation: 335

Post » Wed Feb 18, 2015 8:44 am

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.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: irbis, yuji567 and 11 guests