Hi! I'm trying to make a node that when hit kills the player but when i hit the node i get an error:
AsyncErr: Lua: Runtime error from mod 'mod1' in callback node_on_punch(): /minetest/bin/../mods/mod1/init.lua:11: attempt to call field 'set_hp' (a nil value)
stack traceback:
/minetest/bin/../mods/mod1/init.lua:11: in function </minetest/bin/../mods/mod1/init.lua:10>
Here's the code:
local name = minetest.localplayer
local player = minetest.get_player_by_name(name)
You need to use the player object from within the on_punch function. The on_punch function is called with several arguments without you having to care about them manually.
You should also make sure that the puncher of a node is an actual player.
You need to use the player object from within the on_punch function. The on_punch function is called with several arguments without you having to care about them manually.
You should also make sure that the puncher of a node is an actual player.
Oh. Didn't know that. Thanks a lot Linuxdirk! I thought that you need to pass your own variables as arguments to the function.
You're welcome :) In the function you can only use things that are provided by the API (like the parameters in this specific order) or that you create or get from within this function.
I suggest only using the Lua API documentation file as reference on how to use API functions. The dev wiki's documentation on API calls is commonly seen as just outdated at best. All other sources are just 3rd-party sources not to be used as only reference.