Custom Object ID doesn't work

Hello,
I create 4 instances of one object using variable “Object Number” to recognize each one:

But when a I run the game all instances have the same “Object Number” value.
image

1


2

3

4

Why ? Is it possibile to attribuite 4 different values ?

Thanks,
J

Crazy idea, but I have notice, if I don’t check for the ID value of the object being 0, somehow, even the objects not being created, grab the value of the id.

Try it with a test event like:
Scene variable ID = 1
repeat 4 times
- create object
- if object.variable(ID) = 0, the make object.variable(ID) = Scene Variable(ID), Scene Variable ID add 1

For the events you are using:

  • Create Object at pos X,Y
  • Change Variable Value to 1
  • Create Object at pos X, Y
    - If Variable Value = 0 then Variable Value = 2
  • Create Object at pos X, Y
    - if Variable Value = 0 then Variable Value = 3
  • Create Object at pos X, Y
    - if Variable Value = 0 then Variable Value = 4

It is kinda tricky, but Gdevelop isn’t taking only the last created object to assign the value, but each and every object created.

Another aproach, yet not sure if it works, even if logic says it could is

  • Create object at pos X, Y
    • Variable Value = 1 (Putting the assignation event as a sub event for the creation of the object)

I hope I didn’t confussed you even more.

Hi I don’t know if the intension is to have unique ids in your objects but if that is the case you can use an Extension of @arthuro555 it’s easy to use and maybe never fail on assigning unique ids to your objects

@ UlisesFreitas Thank for you suggestment but I need that the ID are progressive numbers.

Thanks for your help.
“Putting the assignation event as a sub event for the creation of the object” Good Idea but It doesn’t work.
I found 2 solutions but your is the best:
1- create in Editor the instance and value the ID. Then in code identify each ogbject using the ID
At begin of scene:
For each object:
if object.variable(ID) = 1 then put the object X = 10, Y = 20.
if object.variable(ID) = 2 then put the object X = 50, Y = 80.
and so on

2 Your fantastic idea: if object.variable(ID) = 0, the make object.variable(ID) = Scene Variable(ID), Scene Variable ID add 1

Thanks,
J

You are welcome. Always happy to help