How does Lua differentiate identical instances?

Let’s say there are two identical instances with the same class and the same name. How does Lua differentiate instance #1 and instance #2 without getting mixed up? Is there a unique tag assigned to each instance when created that tells the two apart? If so, is it possible for me to utilise them to differentiate identical instances?

1 Like

you would compare properties maybe but if they are 100% the same (besides the debugID) then there wouldn’t really be a reason to differentiate between them, just choose one and clone it for your task.

They would be the same, unless you yourself have an address to the object itself. In memory, they are obviously different. So either use a reference variable to refer to the cloned instance, or pass on a reference (using a modulescript or otherwise that can hold tables of data).

2 Likes

↑ this. obviously it depends on your use case, but if you’re using a plugin (or command bar), Instances have a GetDebugId method, which returns a unique ID for the Instance.

when using a normal script, you’ll find that Instance1 ~= Instance2 because of their unique IDs.

1 Like