How To Find The Latest Summoned Unit?


#1

I’m trying to add units to array as soon as they are summoned i want each of them to move to a unique location in the order of their summoning. Is there any way to find the latest summoned unit? Thanks In Advance


#2

Nevermind I got it xD Please Remove This Post


#3

It’s generally a good idea to explain how you got it. That way other users who might be looking for the same answers don’t have to make new threads.

I’ve found that this works:

latest = self.built[len(self.built)-1]

(Python)


#4

Actually my method is a little different. I found out that the units we summon will always be arranged in the order they are summoned like if there are already 5 soldiers on the field and i summon one archer and one griffinrider then the archer will be the 6th and the griffinrider will be the 7th. Hence The Latest Summoned Unit Will Be The Last In Friends Array. Sorry For Not Sharing My Findings I thought it was basic stuff which everybody already knows.
Example:-

loop:
      summon("soldier")
      friends = findfFriends()
      lastIndex = len(friends)
      latestSummoned = friends[lastIndex}

#5

Yeah, that’s one way to do it. That will only work if none of the friends have died, though, whereas the built array still keeps dead units, so it won’t move around on you.