How do I get Uid of an Sprite every time layout restarted

Get help using Construct 2

Post » Thu Nov 24, 2016 9:08 am

Hi , I have a restart button on game and when user clicked on that,the layout will be restarted and in this game an sprite created many times , I want to get uid of first of this sprite has been created every time layout restarted , note : some times sprites destroyed then uid of first sprite in every restart will be changed , Forgive me for my bad english :D
B
4
Posts: 26
Reputation: 252

Post » Thu Nov 24, 2016 10:17 am

I don't know if I understand you correct. Sorry if isn't what you want.
If you want the first sprite of several instances of this sprite, I would use the IID not the UID. The IID is a number in ascending order number starts with 0 for the first sprite.
You can then easily access a sprite with a definite number with the condition 'pick nth instance'.

For example the first sprite with IID=0:

System| Pick Sprite instance 0
B
24
S
3
G
1
Posts: 454
Reputation: 2,171

Post » Thu Nov 24, 2016 10:30 am

Asmodean wrote:I don't know if I understand you correct. Sorry if isn't what you want.
If you want the first sprite of several instances of this sprite, I would use the IID not the UID. The IID is a number in ascending order number starts with 0 for the first sprite.
You can then easily access a sprite with a definite number with the condition 'pick nth instance'.

For example the first sprite with IID=0:

System| Pick Sprite instance 0

Yes your idea is correct but in this layout every 2 second that sprite is creating in top of layout and every tick it's moving to bottom of layout , after this sprite goes out of layout it will be destroyed and on the other in same time in most possible I have 2 of that in the view and iid of that spite is changed when other sprite has been destroyed (first one's iid = 0 and next one's iid will be 1 after destroying first sprite, next sprite's iid will be changed to 0 and its make my code inefficient :D )
B
4
Posts: 26
Reputation: 252

Post » Thu Nov 24, 2016 1:20 pm

You could have a variable that counts how many objects have been created and resets when the layout start.

Something like:

tempFirstSpriteCount=0
tempFirstSpriteUID=0
------
If tempFirstSpriteCount is equal to 0 -> set tempFirstSpriteUID to sprite.UID
------
every 2 seconds -> create sprite
add 1 to tempFirstSpriteCount
B
125
S
43
G
41
Posts: 849
Reputation: 28,260


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Google [Bot], matriax and 8 guests