-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add uuid to ObjectRefs for tracking objects between loads #5012
Comments
It is actually possible to iterate though minetest.luaentities and compare the objectRefs directly so step 1 is not strictly necessary, however, this would be a very useful feature. |
I don't know if comparing the ObjectRefs directly will work. Lua can only compare pointers, and if both are different, they will not match. |
You may well be right there, I don't know enough about the inner workings to comment but code like this has worked seemingly reliably for me in the past. local function get_object_id(object)
for id, entity in pairs(minetest.luaentities) do
if entity.object == object then
return id
end
end
end |
OK, when experience proved it... |
I totally agree, this is a much needed feature for more advanced uses of SAOs that needs to be implemented in a proper way. |
I second this request. I'm taking a stab at using Lua entities for ambient sounds, and it would really help to have access to the active object IDs so that I could track when they are loaded and unloaded in the environment, similar to the implementation that orwell96 is suggesting above. This should be an extremely easy change to the API since server active objects already have a getId( ) method in the parent class. Something like this in l_object.cpp perhaps?
|
Is the object ID allocated when the object is loaded? If so, there's the possibility of IDs being reused which could cause obscure bugs |
@rubenwardy little chance to be re-used as it's incremented on each entity and it's a u64 |
Old issue, is this supported by any core devs? I assume yes from the comments but please add the label if you do. |
Relevant IRC discussion from yesterday: |
I support this and I think sfan5 does too |
aren't object IDs u16? they currently do get re-used; object_ids are not unique over time, only at any given moment. it's possible that the id points to a different object when you do a check. minetest/src/activeobjectmgr.h Lines 47 to 65 in 25c5400
or has this become a proposal to increase the size of the id? i notice the title of the issue has changed, though the reasoning for that might have been on IRC...
this works currently, but i thought this was discouraged? Lines 6943 to 6952 in f680d10
|
#11050 btw |
I have an ObjectRef and want to get it's Active Object ID.
Getting the active object ID of objects is hard, there seems to be only one way:
There should be an API call for ObjectRefs "object:get_id()" to get its ActiveObjectID.
Reason why I need this:
I want to check if certain entities are still loaded from a globalstep, by storing their ActiveObjectID in a table and looking if the ObjectRef still resides in minetest.object_refs
BTW, a reliable method to check if a stored ObjectRef is still loaded/associated to an SAO is to call object:getyaw(). If it returns nil, it is not.
The text was updated successfully, but these errors were encountered: