Unique ID for specific object

This forum is currently in read-only mode.
  • 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..

  • if I insert a new object it will just mess it up as the object's ID will have changed..

    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

  • thanks, I'll try that.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)