Problem with minetest.add_entity

User avatar
Posts: 1070
Joined: Thu Apr 25, 2013 17:29
Location: SP-Brasil
GitHub: BrunoMine

Problem with minetest.add_entity

by BrunoMine » Fri Apr 27, 2018 17:48

my code:
Code: Select all
local obj = minetest.add_entity(spos, "sunos:npc_"..tipo, {sunos_registrado = false}) -- Cria o mob

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
Posts: 923
Joined: Sat Feb 02, 2013 02:51
Location: United Kingdom
GitHub: stujones11

Re: Problem with minetest.add_entity

by stu » Sun Apr 29, 2018 15:52

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})

Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 3 guests