Target last clone

Non-platform specific questions.

Target last clone

Postby lverona » Sat Jul 27, 2013 6:15 pm

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?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Target last clone

Postby skydereign » Sat Jul 27, 2013 11:01 pm

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Target last clone

Postby lverona » Sat Jul 27, 2013 11:14 pm

I can actually wait a frame if necessary I think. I will try to figure out how to do that. Thanks for advice ;)
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: Target last clone

Postby lverona » Sun Jul 28, 2013 5:54 pm

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.
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron