I think the title says it all. If you didn’t know, each value in Roblox has a memory location. I believe that each Instance also has a unique memory location that can be referred to and iterated by Lua. Is there a way I can fetch the memory location of an Instance?
Example:
local sounds = {}
local sound = Instance.new("Sound")
sounds[sound.MEMORY_LOCATION] = sound
The code above will let me store each value by a unique id which also happens to be their memory location too.
Yeah that would be great, but that defeats the whole point of the system. I want a unique id for each value which may later be called upon for deletion of the instance by the client.
The “memory location” of an instance is not what you want here. If you need a unique id for each instance use HttpService:GenerateGUID?
local HttpService = game:GetService("HttpService")
local function generate_instance_with_id(class_name, include_brackets)
return Instance.new(class_name), HttpService:GenerateGUID(include_brackets)
end
local instance, id = generate_instance_with_id("Sound", true)
print(instance, id)
local instance2, id2 = generate_instance_with_id("Sound", true)
print(instance2, id2)
Okay, that is a good solution. It would be awesome to use the UUID (which I will, thanks ), but that does not answer the question: How to get the memory location of an instance
you don’t, and you don’t need to. you want a way to uniquely identify without using the instance itself for some reason, not because of memory manipulation or whatever
Just want to bump to ask if this is possible at all, as that wasn’t answered yet in this thread. Would like to use this for some niche debugging stuff. Thanks!
In theory you could print out a table with instance keys, e.g ={ [workspace] = true }, as the expressive output will print it as { [Instance(id)] = true } since the instance ID is printed rather than the name/path. However, I don’t think you can get this result outside of studio, since AFAIK the pretty printing characteristic is only found in studio’s output, and not the in-game developer console. I still stand by my original posts tho.