set_node error

Post Reply
IniKiwi
New member
Posts: 5
Joined: Fri Jun 02, 2023 19:03
GitHub: IniKiwi
In-game: IniKiwi

set_node error

by IniKiwi » Post

hello! I code a game and I have a problem. I made a decoration that place "place_tree".
in the ikw.tree_branch function the first set_node function works but not the second not working

Code: Select all

function ikw.tree_branch(pos, axis, leaves, tree, leave_radius, leave_height)
    minetest.set_node(pos,  {name = tree, param2 = axis})
    for h = 0, leave_height do
        for x = -(leave_radius-h), (leave_radius-h) do
            for z = -(leave_radius-h), (leave_radius-h) do
                minetest.set_node({x = pos.x+x, y = pos.y+h+1, z = pos.z+z}, leaves)
            end
        end
    end
end

minetest.register_node("ikw:place_tree", {
    on_construct = function(pos)
        ikw.tree_branch(pos, 2, "ikw:leaves", "ikw:tree", 4, 3)
    end
})

Code: Select all

2023-06-02 19:30:48: ACTION[Server]: singleplayer places node ikw:place_tree at (98,15,133)
2023-06-02 19:30:48: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'ikw' in callback item_OnPlace(): Runtime error from mod 'ikw' in callback node_on_construct(): /usr/local/share/minetest/builtin/common/item_s.lua:190: bad argument #1 to 'old_get_content_id' (string expe
2023-06-02 19:30:48: ERROR[Main]: cted, got nil)
2023-06-02 19:30:48: ERROR[Main]: stack traceback:
2023-06-02 19:30:48: ERROR[Main]: 	[C]: ?
2023-06-02 19:30:48: ERROR[Main]: 	[C]: in function 'old_get_content_id'
2023-06-02 19:30:48: ERROR[Main]: 	/usr/local/share/minetest/builtin/common/item_s.lua:190: in function </usr/local/share/minetest/builtin/common/item_s.lua:189>
2023-06-02 19:30:48: ERROR[Main]: 	/usr/local/share/minetest/builtin/common/item_s.lua:229: in function </usr/local/share/minetest/builtin/common/item_s.lua:228>
2023-06-02 19:30:48: ERROR[Main]: 	[C]: in function 'set_node'
2023-06-02 19:30:48: ERROR[Main]: 	...rre/.minetest/games/IniKiwi-World/mods/ikw/trees.lua:9: in function 'tree_branch'
2023-06-02 19:30:48: ERROR[Main]: 	...rre/.minetest/games/IniKiwi-World/mods/ikw/trees.lua:23: in function <...rre/.minetest/games/IniKiwi-World/mods/ikw/trees.lua:22>
2023-06-02 19:30:48: ERROR[Main]: 	[C]: in function 'add_node'
2023-06-02 19:30:48: ERROR[Main]: 	/usr/local/share/minetest/builtin/game/item.lua:255: in function </usr/local/share/minetest/builtin/game/item.lua:146>
2023-06-02 19:30:48: ERROR[Main]: 	(tail call): ?
2023-06-02 19:30:48: ERROR[Main]: 	(tail call): ?
2023-06-02 19:30:48: ERROR[Main]: stack traceback:
2023-06-02 19:30:48: ERROR[Main]: 	[C]: ?
2023-06-02 19:30:48: ERROR[Main]: 	[C]: in function 'add_node'
2023-06-02 19:30:48: ERROR[Main]: 	/usr/local/share/minetest/builtin/game/item.lua:255: in function </usr/local/share/minetest/builtin/game/item.lua:146>
2023-06-02 19:30:48: ERROR[Main]: 	(tail call): ?
2023-06-02 19:30:48: ERROR[Main]: 	(tail call): ?

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: set_node error

by Desour » Post

You're passing a string ("ikw:leaves") instead of a node table to set_node.
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

User avatar
cx384
Member
Posts: 653
Joined: Wed Apr 23, 2014 09:38
GitHub: cx384
IRC: cx384

Re: set_node error

by cx384 » Post

replace

Code: Select all

minetest.set_node({x = pos.x+x, y = pos.y+h+1, z = pos.z+z}, leaves)
with

Code: Select all

minetest.set_node({x = pos.x+x, y = pos.y+h+1, z = pos.z+z}, name=leaves})
to fix this


Also please try to read the error message yourself, it clearly indices where your problem is and read the documentation carefully, to fix something like for yourself this in the future.

Code: Select all

...
* `minetest.set_node(pos, node)`
* `minetest.add_node(pos, node)`: alias to `minetest.set_node`
    * Set node at position `pos`
    * `node`: table `{name=string, param1=number, param2=number}`
...
https://github.com/minetest/minetest/bl ... ent-access
Can your read this?

User avatar
TenPlus1
Member
Posts: 3715
Joined: Mon Jul 29, 2013 13:38
In-game: TenPlus1
Contact:

Re: set_node error

by TenPlus1 » Post

leaves should be {node = "ikw:leaves}

User avatar
Desour
Member
Posts: 1469
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: set_node error

by Desour » Post

TenPlus1 wrote:
Sat Jun 03, 2023 05:29
leaves should be {node = "ikw:leaves}
{name = "ikw:leaves"}
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests