rubenwardy/ChatCmdBuilder

issue getting to work

Closed this issue · 10 comments

I am having trouble getting this to work, I noticed it has not been updated in a while so I wanted to check to see if it was technically still functional. I copied your init.lua into my mod folder and renamed it like your documentation in the modding textbook stated to do doing a dofile, this following code is at the top of my file dofile("ChatCmdBuilder.lua") This next segment of my code was at the end of my file

ChatCmdBuilder.new("money", function(cmd)
	cmd:sub("send :to :ammount", function(name, to, ammount)
		local player = minetest.get_player_by_name(target)
		if player then
			money.send(player:get_player_name(), to, ammount)
		end
	end)
end, {
	description = "Momey mod for MineTest",
	privs = {
		basic_privs
	}
}

Here is a copy of the debug.txt that I have no clue how to read

-------------
  Separator
-------------

2017-07-11 02:44:35: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2017-07-11 02:44:35: ERROR[Main]: ModError: Failed to load and run script from C:\Users\austin\Documents\minetest-0.4.16-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:
2017-07-11 02:44:35: ERROR[Main]: Mod security: Blocked attempted read from ChatCmdBuilder.lua
2017-07-11 02:44:35: ERROR[Main]: stack traceback:
2017-07-11 02:44:35: ERROR[Main]: 	[C]: in function 'dofile'
2017-07-11 02:44:35: ERROR[Main]: 	...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:13: in main chunk
2017-07-11 02:44:35: ERROR[Main]: Check debug.txt for details.
2017-07-11 02:50:26: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2017-07-11 02:50:26: ERROR[Main]: ModError: Failed to load and run script from C:\Users\austin\Documents\minetest-0.4.16-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:
2017-07-11 02:50:26: ERROR[Main]: ...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:214: unexpected symbol near ')'
2017-07-11 02:50:26: ERROR[Main]: Check debug.txt for details.
2017-07-11 02:51:13: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2017-07-11 02:51:13: ERROR[Main]: ModError: Failed to load and run script from C:\Users\austin\Documents\minetest-0.4.16-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:
2017-07-11 02:51:13: ERROR[Main]: Mod security: Blocked attempted read from ChatCmdBuilder.lua
2017-07-11 02:51:13: ERROR[Main]: stack traceback:
2017-07-11 02:51:13: ERROR[Main]: 	[C]: in function 'dofile'
2017-07-11 02:51:13: ERROR[Main]: 	...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:13: in main chunk
2017-07-11 02:51:13: ERROR[Main]: Check debug.txt for details.
2017-07-11 02:55:59: WARNING[Main]: Assignment to undeclared global "ret" inside a function at ...est-0.4.16-win64\bin\..\builtin\mainmenu\tab_credits.lua:77.

That's very odd, this library doesn't use the file system at all.

Are you calling dofile() at load time?

I believe so, I have not programmed in lua outside of computercraft so all of my coding experience is from c, java, and php. the dofile() is the first line of actual code (first line not commented out when I run it) Here is a link to my repository, the master branch is functional code and the dev branch has where I attempted to use your mod, the code is commented out so I could try doing it another way but everything I did is there.
https://github.com/apachano/minetest-money/tree/development

aaah, it needs to be this:

dofile(minetest.get_modpath("money") .. "/ChatCmdBuilder.lua")

instead of

dofile("ChatCmdBuilder.lua")

I changed it to the way you suggested, I have been spending a ton of time trying to get it to work. This is what the output shows.

2017-07-11 16:23:04: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2017-07-11 16:23:04: ACTION[Main]: [money] money.mt opened.
2017-07-11 16:23:04: [Main]: [money] money.mt successfully read.
2017-07-11 16:23:04: WARNING[Main]: Undeclared global variable "ChatCmdBuilder" accessed at ...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:249
2017-07-11 16:23:04: ERROR[Main]: ModError: Failed to load and run script from C:\Users\austin\Documents\minetest-0.4.16-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:
2017-07-11 16:23:04: ERROR[Main]: ...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:249: attempt to index global 'ChatCmdBuilder' (a nil value)
2017-07-11 16:23:04: ERROR[Main]: stack traceback:
2017-07-11 16:23:04: ERROR[Main]: 	...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:249: in main chunk
2017-07-11 16:23:04: ERROR[Main]: Check debug.txt for details.

Hi, try updating ChatCmdBuilder.lua and trying again. I hopefully fixed it

It still does not work. Here is the latest error log it gives me.

2017-07-11 21:15:32: WARNING[Main]: NodeDefManager: Ignoring CONTENT_IGNORE redefinition
2017-07-11 21:15:32: ACTION[Main]: [money] money.mt opened.
2017-07-11 21:15:32: [Main]: [money] money.mt successfully read.
2017-07-11 21:15:32: WARNING[Main]: Undeclared global variable "basic_privs" accessed at ...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:263
2017-07-11 21:15:32: ERROR[Main]: ModError: Failed to load and run script from C:\Users\austin\Documents\minetest-0.4.16-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:
2017-07-11 21:15:32: ERROR[Main]: ...netest-0.4.16-win64\bin\..\mods\money/ChatCmdBuilder.lua:133: attempt to call local 'func' (a string value)
2017-07-11 21:15:32: ERROR[Main]: stack traceback:
2017-07-11 21:15:32: ERROR[Main]: 	...netest-0.4.16-win64\bin\..\mods\money/ChatCmdBuilder.lua:133: in function 'build'
2017-07-11 21:15:32: ERROR[Main]: 	...netest-0.4.16-win64\bin\..\mods\money/ChatCmdBuilder.lua:5: in function 'new'
2017-07-11 21:15:32: ERROR[Main]: 	...6-win64\minetest-0.4.16-win64\bin\..\mods\money\init.lua:249: in main chunk
2017-07-11 21:15:32: ERROR[Main]: Check debug.txt for details.

I fixed the issue and got the mods to compile. in your code on line you call local cmd = ChatCmdBuilder.build(name, func) but when you define the function on line 35 it does not ask for a name to be passed to it function ChatCmdBuilder.build(func) if you make them match the code compiles and the game runs.

Here is the next issue I am having, I set up a command as follows

ChatCmdBuilder.new("adminmoney", 
	function(cmd)
		cmd:sub("give :to :amount:int", function(to, amount)
			if money.playerlist[to] ~= nil then
				--money.add(to, amount)
				minetest.chat_send_player("SonosFuer", "to: " .. to .. " amount: " .. amount)
				return true
			else
				return false, "player does not exist"
			end
		end)
	end, {
		description = "admin money command",
		privs = {
			basic_privs
		}
	}
)

When I run the command adminmoney give SonosFuer 100 it writes to: SonosFuer amount: SonosFuer which means somewhere in the parsing it is not catching the second parameter and it is just returning the first for both. I hate reg expressions (never could memorize all that stuff) so I am having a hard time looking through the code to even see what is going on but I will keep working.

The function should be name, to, amount, not to, amount

That makes sense, it works perfectly now. Thank you very much for all of your help.