Here's the offending code snippet, from my init.lua:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local child = minetest.add_entity(pos, 'evolvingcells:cell');
if child ~= nil then
minetest.log("Created a " .. type(child));
child.dna = mutate(child.dna);
end
When this code runs, the fourth line causes a crash, with the error "attempt to index local 'child' (a userdata value)".
The log output also reports that 'child' is indeed a userdata value, rather than the ObjectRef (table) I expected it to be.
I looked around for this error to see whether I was making a simple mistake, and found a wiki page which mentions this error being caused by not correctly registering a class before using it, but I don't quite understand what I need to register or how to do so. The function containing this snippet is part of the prototype for my cell entity, so I don't believe that I can register the cell entity before defining this function.
Is there a way for me to get the ObjectRef (or LuaEntitySAO) of my newly-created 'child' entity, as I have attempted to do here?