How to access the "giveme" pls help

Post Reply
User avatar
Ta1ls
New member
Posts: 7
Joined: Sat Sep 22, 2018 19:35
In-game: Tails

How to access the "giveme" pls help

by Ta1ls » Post

I used to be "Tails", but my account was blocked :( anyway,

Code: Select all

minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
   if node.name == "tutorial:greenbox" then
	function giveme("tutorial:greentoy")
)
It says this message from debug.txt...
"2018-09-22 14:40:03: ERROR[Main]: ModError: Failed to load and run script from C:\Users\Someone\Programs\minetest-0.4.17.1-win64\bin\..\mods\tutorial\init.lua:
2018-09-22 14:40:03: ERROR[Main]: ...ograms\minetest-0.4.17.1-win64\bin\..\mods\tutorial\init.lua:76: <name> or '...' expected near '"tutorial:greentoy"'
2018-09-22 14:40:03: ERROR[Main]: Check debug.txt for details.

please help! :)

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to access the "giveme" pls help

by Krock » Post

Executing /giveme: (the ugly-but-works way)

Code: Select all

-- In the node definition of "tutorial:greenbox":
	on_punch = function(pos, node, puncher, pointed_thing)
		if node.name == "tutorial:greenbox" then
			minetest.registered_chatcommands["giveme"].func(puncher:get_player_name(), "tutorial:greentoy")
		end
	end,
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Linuxdirk
Member
Posts: 3219
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: How to access the "giveme" pls help

by Linuxdirk » Post

Doing it by using the API functions for inventory manipulation:

Code: Select all

minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
    if node.name == "tutorial:greenbox" then
        puncher:get_inventory():add_item("main", "tutorial:greentoy")
    end
end)
But as already implied by Krock: Do not add this functionality globally via the register_on function but only in your node definition (works the same there).

User avatar
Ta1ls
New member
Posts: 7
Joined: Sat Sep 22, 2018 19:35
In-game: Tails

Re: How to access the "giveme" pls help

by Ta1ls » Post

Thanks you guys! :) it works!

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests