Page 1 of 1

[SOLVED] get_objects_inside_radius returns objs with no name

PostPosted: Sun Aug 28, 2016 01:01
by taikedz
Hello

I am trying to dereference the name of an object obtained from get_objects_inside radius - but they do not seem to have a name property. Have I misunderstood how to extract the name at this stage, or is there really no name?

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
                if pointed_thing.type ~= "node" then
                        if not pointed_thing.ref then return end
                        local mob = pointed_thing.ref
                        local mobe = mob:get_luaentity()

                        if mob:is_player() then return end

                        for _,obj in pairs(minetest.get_objects_inside_radius(mob:getpos() ,radius)) do
                                --if mobe.name == obj:get_luaentity().name then -- crashes, attempted index a nil value (name)
                                if mobe.name == obj:get_luaentity() then -- this produces debug showing the lua entity is indeed returned without a name
                                        vivarium:bomf(obj:getpos(),1 )
                                        obj:remove()
                                else
                                        minetest.debug(mobe.name.." is not "..dump(obj:get_luaentity() ))
                                        -- the debug shows it has no "name" property
                                        -- note: mob.name is correctly set
                                end
                        end
                        return
                end


For the code in its context see https://github.com/taikedz/vivarium/blo ... #L346-L355

Re: get_objects_inside_radius returns objects with no name

PostPosted: Sun Aug 28, 2016 01:38
by BrandonReese
get_objects_inside_radius also gets players, dropped items, etc... so you'll need to check for obj:is_player in the for loop and check that .name ~= nil or some other property that will help you identify whether it's actually a mob or not.

Re: get_objects_inside_radius returns objects with no name

PostPosted: Sun Aug 28, 2016 03:33
by taikedz
Noted. I do a player check already (see code snippet). Will add an object check. (That said, I would expect a dropped item to have a name. I would actually expect everything except players to have a name.)

Still does not answer why entities that are indeed mobs are not returning with their name, since the debug clearly shows the entity data being from a mob (switched the chat_send_all to a debug in the debugging line):

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
mobs_senderman:senderman is not {
   base_size = {
      y = 6,
      x = 6
   },
   base_mesh = "sender_man.x",
   health = 17,
   old_y = 82.51000213623,
   mesh = "sender_man.x",
   time_of_day = 0.17550000548363,
   collisionbox = {
      -0.5,
      -0.01,
      -0.5,
      0.5,
      5.4,
      0.5
   },
   object = <userdata>,
   remove_ok = true,
   attack = <userdata>,
   textures = {
      "sender_man.png"
   },
   base_texture = {
      "sender_man.png"
   },
   timer = 14.591999964789,
   path = {
      stuck = false,
      following = false,
      way = {
         
      },
      lastpos = {
         y = 0,
         x = 0,
         z = 0
      },
      stuck_timer = 0
   },
   old_health = 17,
   env_damage_timer = 0.31000000983477,
   standing_in = "air",
   state = "attack",
   base_colbox = {
      -0.5,
      -0.01,
      -0.5,
      0.5,
      5.4,
      0.5
   },
   visual_size = {
      y = 6,
      x = 6
   },
   lifetimer = 99.183999054127
}

Re: get_objects_inside_radius returns objects with no name

PostPosted: Sun Aug 28, 2016 21:41
by Byakuren
Index a nil value means the table you are indexing is nil. In this case, obj:get_luaentity(). It probably means obj is a player; the earlier player check does not help you here, because it's a different object. You wouldn't get an error just because name is nil.

Re: get_objects_inside_radius returns objects with no name

PostPosted: Mon Aug 29, 2016 18:10
by taikedz
Byakuren wrote:Index a nil value means the table you are indexing is nil. In this case, obj:get_luaentity(). It probably means obj is a player; the earlier player check does not help you here, because it's a different object. You wouldn't get an error just because name is nil.


The debug dump indicates otherwise.

Re: get_objects_inside_radius returns objects with no name

PostPosted: Mon Aug 29, 2016 23:25
by Byakuren
taikedz wrote:
Byakuren wrote:Index a nil value means the table you are indexing is nil. In this case, obj:get_luaentity(). It probably means obj is a player; the earlier player check does not help you here, because it's a different object. You wouldn't get an error just because name is nil.


The debug dump indicates otherwise.

The debug dump indicates that mobe has no name field. I am talking about obj, not mobe.

Here is a reannotated version of your code:
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
                if pointed_thing.type ~= "node" then
                        if not pointed_thing.ref then return end
                        local mob = pointed_thing.ref
                        local mobe = mob:get_luaentity()

                        if mob:is_player() then return end

                        for _,obj in pairs(minetest.get_objects_inside_radius(mob:getpos() ,radius)) do
                                --if mobe.name == obj:get_luaentity().name then -- crashes, attempted index a nil value (obj:get_luaentity())
                                if mobe.name == obj:get_luaentity() then -- this is false, because obj:get_luaentity() is nil, while mobe.name is not nil
                                        vivarium:bomf(obj:getpos(),1 )
                                        obj:remove()
                                else
                                        minetest.debug(mobe.name.." is not "..dump(obj:get_luaentity() ))
                                        -- the debug shows that obj:get_luaentity() is not the same as mobe.name, since obj:get_luaentity() is nil
                                        -- note: mob.name is correctly set
                                end
                        end
                        return
                end

Re: get_objects_inside_radius returns objects with no name

PostPosted: Tue Aug 30, 2016 02:42
by taikedz
Byakuren wrote:The debug dump indicates that mobe has no name field. I am talking about obj, not mobe.

Here is a reannotated version of your code:
(snip)


Thanks, however that's still not it.

I appreciate I may have left some remnants of my debugging that may have confused what I posted, so I have cleared it up, and taken into account your suggestion to check the object rather than the lua entity, as well as checking for players:

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
                if pointed_thing.type ~= "node" then
                        if not pointed_thing.ref then return end
                        local mob = pointed_thing.ref
                        local mobe = mob:get_luaentity()

                        if mob:is_player() then return end

                        minetest.debug("Mob clicked: "..tostring(mobe.name))
                        for _,obj in pairs(minetest.get_objects_inside_radius(mob:getpos() ,radius)) do
                                if not obj:is_player() then

                                minetest.debug("Obj: "..dump(obj))
                                local oname = obj.name or "nothing"
                                minetest.debug("Obj name: "..oname)
                                minetest.debug("Obj: "..dump(obj:get_luaentity() ))

                                        vivarium:bomf(obj:getpos(),1 )
                                        obj:remove()
                                else
                                        minetest.debug("got a player - skipped")
                                end -- playercheck
                        end
                        return
                end


And the resulting debug. Player is detected and skipped, panda object has no name, panda lua entity has no name.

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
2016-08-30 03:35:42: [Server]: Mob clicked: dmobs:panda
2016-08-30 03:35:42: [Server]: got a player - skipped
2016-08-30 03:35:42: [Server]: Obj: <userdata>
2016-08-30 03:35:42: [Server]: Obj name: nothing
2016-08-30 03:35:42: [Server]: Obj: {
        base_size = {
                y = 1,
                x = 1
        },
        base_mesh = "panda.b3d",
        health = 18,
        old_y = 48,
        mesh = "panda.b3d",
        time_of_day = 0.75358331203461,
        collisionbox = {
                -0.4,
                -0.5,
                -0.4,
                0.4,
                0.5,
                0.4
        },
        object = <userdata>,
        remove_ok = true,
        textures = {
                "dmobs_panda.png"
        },
        base_texture = {
                "dmobs_panda.png"
        },
        timer = 0.10799999907613,
        path = {
                stuck = false,
                following = false,
                way = {
                       
                },
                lastpos = {
                        y = 0,
                        x = 0,
                        z = 0
                },
                stuck_timer = 0
        },
        env_damage_timer = 0,
        lifetimer = 175.81099998765,
        old_health = 18,
        state = "walk",
        standing_in = "air",
        visual_size = {
                y = 1,
                x = 1
        },
        base_colbox = {
                -0.4,
                -0.5,
                -0.4,
                0.4,
                0.5,
                0.4
        }
}
2016-08-30 03:35:42: WARNING[Server]: Deprecated add_particlespawner call with individual parameters instead of definition
2016-08-30 03:35:42: [Server]: Obj: <userdata>
2016-08-30 03:35:42: [Server]: Obj name: nothing
2016-08-30 03:35:42: [Server]: Obj: {
        base_size = {
                y = 1,
                x = 1
        },
        base_mesh = "panda.b3d",
        health = 20,
        old_y = 49,
        mesh = "panda.b3d",
        time_of_day = 0.75358331203461,
        collisionbox = {
                -0.4,
                -0.5,
                -0.4,
                0.4,
                0.5,
                0.4
        },
        object = <userdata>,
        remove_ok = true,
        textures = {
                "dmobs_panda.png"
        },
        base_texture = {
                "dmobs_panda.png"
        },
        timer = 0.10799999907613,
        path = {
                stuck = false,
                following = false,
                way = {
                       
                },
                lastpos = {
                        y = 0,
                        x = 0,
                        z = 0
                },
                stuck_timer = 0
        },
        env_damage_timer = 0,
        lifetimer = 177.85100000724,
        old_health = 20,
        state = "walk",
        standing_in = "air",
        visual_size = {
                y = 1,
                x = 1
        },
        base_colbox = {
                -0.4,
                -0.5,
                -0.4,
                0.4,
                0.5,
                0.4
        }
}

Re: get_objects_inside_radius returns objects with no name

PostPosted: Tue Aug 30, 2016 06:33
by Byakuren
Can you try getting .name by indexing, like you did with the object? luaentities might use metatables to provide a .name that isn't actually part of the table.

Re: get_objects_inside_radius returns objects with no name

PostPosted: Tue Aug 30, 2016 12:43
by BrandonReese
It would seem whatever mob mod you are using doesn't set a name when it registers the entity.

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
function mobs:register_mob(name, def)
   minetest.register_entity(name, {
      name = name,


In the register mob function where it registers the entity it should also set a name parameter like above. If it doesn't there is no way to get the name. There is a get_entity_name function but it says it's depreciated and will be removed. I assume it would be used like this: mobe.object:get_entity_name()

Re: get_objects_inside_radius returns objects with no name

PostPosted: Tue Aug 30, 2016 12:51
by taikedz
Byakuren wrote:Can you try getting .name by indexing, like you did with the object?


I thought that was indexing what I did when calling the "obj.name" which is what I did on the object.... sory but maybe my parsing brain is not on today

Byakuren wrote:luaentities might use metatables to provide a .name that isn't actually part of the table.


But I think I got what you meant

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 luae = obj:get_luaentity()

luae.name -- this is nil

luae["name"] -- this gives me the name



What's the difference? I thought they were simply different notation styles.... what is the correct terminology so I can go read up on this please?

Thanks!

Re: [SOLVED] get_objects_inside_radius returns objs with no

PostPosted: Tue Aug 30, 2016 23:07
by Byakuren
There shouldn't be any difference. By indexing I meant to do luae.name instead of dump(luae) to check if the name is nil. foo.bar is just syntax sugar for foo["bar"] so it should always have the same result.

Re: [SOLVED] get_objects_inside_radius returns objs with no

PostPosted: Wed Aug 31, 2016 08:43
by taikedz
Yeah that's what I thought.... might need to do some more checking on this front.... thanks immensely for your help!