Unique ID for specific object

New releases and general discussions.

Post » Wed May 13, 2009 12:00 pm

Since Construct doesn't have a spread value feature, I've been relying on the "unique ID" action. However what I think would be useful is a Unique ID for a specific object, like if I have 8 of the same sprites their unique IDs could be: 1,2,3,4,5,6,7,8.
However at the moment their unique IDs would be more like this: 94,95,96,97,98,99,100,101. Since the unique ID is accounting for all the other objects in the game.
So what I'm saying is, can we get a unique ID that excludes all other objects from the ID?
I've just coded a whole menu system based around using the unique ID thing, but realised that as I add more objects to the game the new objects get an ID which comes before the old object.

So I'm not really sure how I can actually make proper use of this unique ID, as every time I refer to an object according to an ID then if I insert a new object it will just mess it up as the object's ID will have changed..
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Wed May 13, 2009 12:05 pm

[quote="alspal":5y4bnd33]if I insert a new object it will just mess it up as the object's ID will have changed..[/quote:5y4bnd33]
Unique IDs never change - once the runtime has started. There is no guarantee any particular object will ever get any particular unique ID, so you shouldn't refer to pre-set unique IDs in events.

If you need to index objects from 1, just use:

+ For Each Sprite
-> Sprite: set value to LoopIndex
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Wed May 13, 2009 12:08 pm

thanks, I'll try that.
B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

Post » Wed May 13, 2009 9:25 pm

However if you do that and then remove/add elements, they'll do the same as ID.
If you want them to stay orderly numbered, I suggest you implement a stack of UIDs using Array. Then you just reference by the array index. Store the current size somewhere, too.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests