pointed_thing entity name

Post Reply
User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

pointed_thing entity name

by runs » Post

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)

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: pointed_thing entity name

by Pyrollo » Post

[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: pointed_thing entity name

by runs » Post

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.

User avatar
Pyrollo
Developer
Posts: 385
Joined: Mon Jan 08, 2018 15:14
GitHub: pyrollo
In-game: Naj
Location: Paris

Re: pointed_thing entity name

by Pyrollo » Post

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.
[ Display Modpack ] - [ Digiterms ] - [ Crater MG ] - [ LATE ]

User avatar
runs
Member
Posts: 3225
Joined: Sat Oct 27, 2018 08:32

Re: pointed_thing entity name

by runs » Post

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests