Problem with minetest.add_entity

Post Reply
User avatar
BrunoMine
Member
Posts: 1082
Joined: Thu Apr 25, 2013 17:29
GitHub: BrunoMine
Location: SP-Brasil
Contact:

Problem with minetest.add_entity

by BrunoMine » Post

my code:

Code: Select all

local obj = minetest.add_entity(spos, "sunos:npc_"..tipo, {sunos_registrado = false}) -- Cria o mob
debug

Code: Select all

2018-04-27 14:41:59: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod 'sunos' in callback node_on_timer(): ...test-0.4.16/bin/../mods/sociedades/sunos/npc/npc.lua:117: bad argument #3 to 'add_entity' (string expected, got table)
2018-04-27 14:41:59: ERROR[Main]: stack traceback:
2018-04-27 14:41:59: ERROR[Main]: 	[C]: in function 'add_entity'
According to the documentation, this should be a table, not a string.

User avatar
stu
Member
Posts: 923
Joined: Sat Feb 02, 2013 02:51
GitHub: stujones11
Location: United Kingdom

Re: Problem with minetest.add_entity

by stu » Post

BrunoMine wrote:According to the documentation, this should be a table, not a string.
The documentation does not say this should be a table, the square brackets indicate that the argument is optional. Entity `staticdata` is stored as a string, usually this will be a serialized table unless you only need to store a single value.

Edit: On closer inspection the example give on that wiki page is incorrect, it should probably look something like this:

Code: Select all

local staticdata = minetest.serialize({naked = true})
local obj = minetest.add_entity({x=0, y=10, z=0}, "mobs:sheep", staticdata)
if obj then
    obj:setacceleration({x=0, y=-10, z=0})
end

Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 8 guests