Page 1 of 1

Target last clone

PostPosted: Sat Jul 27, 2013 6:15 pm
by lverona
I have several clones of an item. Say, we have 3. When 2 are destroyed, I need to address the one that is left. You do not know which one will be left as the last one.

Then I need to address the last item - like get their position or something else, like item.x and item.y

I thought that when all clones but one are removed, item.x will automatically refer to the last clone. However, this is not always the case and seems to not work reliably.

Is there a way to make this work?

Re: Target last clone

PostPosted: Sat Jul 27, 2013 11:01 pm
by skydereign
The default actor will be updated to the last clone in your example, but only a frame after the others were deleted. Essentially DestroyActor will not actually destroy the actor until the frame ends. In the next version of gE there will be a way to get the last clone, but for it is rather difficult. You can keep track of the highest cloneindex on create, but it is harder to maintain as actors get destroyed.

Re: Target last clone

PostPosted: Sat Jul 27, 2013 11:14 pm
by lverona
I can actually wait a frame if necessary I think. I will try to figure out how to do that. Thanks for advice ;)

Re: Target last clone

PostPosted: Sun Jul 28, 2013 5:54 pm
by lverona
I did this and it works fine, however, sometimes it still does not work.

Here is what I did.
As I collect 2 out of 3 items, I create a special object (it is not seen to the player and is off screen) which in its draw routine has the code to target the last left item. Thus, I actually target it the next frame. I even tried skipping one additional frame using a flag.
After that the special object is destroyed.

It works most of the time. However, sometimes still it won't work. I have no idea why. The code in Draw executes, but the position of the last item is not obtained.

I know it is difficult to advice without seeing the code, however I wonder if there is some other basic GE specific thing I do not know and you might advice.