Page 1 of 1

pointed_thing entity name

Posted: Fri Dec 28, 2018 12:25
by runs
I want to get the name given with 'minetest.register_entity' for a specific entity object.

Code: Select all

local pointed_thing_object = pointed_thing.ref
How can I get the name of this object? (If a player or mob)

Re: pointed_thing entity name

Posted: Fri Dec 28, 2018 12:41
by Pyrollo

Re: pointed_thing entity name

Posted: Fri Dec 28, 2018 19:06
by runs
Pyrollo wrote:From ObjectRef, get_luaentity(), field name
https://dev.minetest.net/ObjectRef
https://dev.minetest.net/LuaEntitySAO
I've tried the following:

Code: Select all

local pointed_thing_object = pointed_thing.ref
local entity = pointed_thing_object:get_luaentity()
if (entity.name == "")
...
...
And it works OK for normal LUA Entities (mobs), but not for players: the server crashes with 'entity.name' being nil.

Any explanation about this?

Well, I could do a workaround checking 'pointed_thing_object:is_player()' and acting in consequence. But I want to know why player.name = nil.

Re: pointed_thing entity name

Posted: Fri Dec 28, 2018 19:56
by Pyrollo
Players are not entities, you have to have two different parts of code for players and entities (yes, using :is_player() :) )
For players, you have to call :get_player_name()
Actually everything is in minetest dev wiki and lua_api.txt.

Re: pointed_thing entity name

Posted: Fri Dec 28, 2018 21:16
by runs
Pyrollo wrote:Players are not entities, you have to have two different parts of code for players and entities (yes, using :is_player() :) )
For players, you have to call :get_player_name()
Actually everything is in minetest dev wiki and lua_api.txt.
Thanx!