ETMods.net

N!tmod, a Wolfenstein: Enemy Territory Modification!

You are not logged in.

Announcement

You can donate to help us keeping services online.

#1 07-Dec-13 15:42:43

NoHero
Member
Registered: 07-Dec-13
Posts: 19

Simple script makes me embarrassed

Since i was testing some server settings on a local server, i thought it be a good time to get to grips with lua scripting. Im no novice at programming and feel ashamed i cant get this little code to work >:[

Can anyone take a look at this and tell me if anything is wrong:

function et_InitGame(levelTime,randomSeed,restart)
	et.RegisterModname("test")
	et.trap_SendServerCommand(-1, "print \"This is a game start message\n\"")
end

function et.ClientCommand( clientNum, command )
	command = string.lower(command)
	if (command == "testcmd") then
		et.trap_SendServerCommand(clientNum, "print \"This is a test cmd\n\"")
		return 1
	end
	return 0
end

/lua_status shows the module loaded, but i always get Unknown Command when i got /testcmd
I have searched and read through many scripts of others, but still cannot figure out where im going wrong. Side note is there a way to debug lua scripts loaded by the mod?

Offline

#2 07-Dec-13 19:00:36

ailmanki
BETA Tester
Registered: 08-Jun-12
Posts: 42
Website

Re: Simple script makes me embarrassed

If I am not mistaken, as I have not tested it...

you have only one small error,
function et.ClientCommand( clientNum, command )
needs to be
function et_ClientCommand( clientNum, command )

I can see why that is confusing.. smile as some commands go with et.*
But basically all function which do use from et go with et_*


b_350_20_692108_381007_FFFFFF_000000.pngb_350_20_692108_381007_FFFFFF_000000.png

Offline

#3 07-Dec-13 20:44:28

NoHero
Member
Registered: 07-Dec-13
Posts: 19

Re: Simple script makes me embarrassed

lol HAHAHAAAA wow thanks man big_smile

I think i copied that from someone elses code snippet, work now with the change. 

Does anyone know a way to output the LUA errors? This is probably something which would of been easily caught if i could see the errors produced. Knowing myself i will most likely make simple mistakes like these in the future.

Offline

#4 07-Dec-13 20:55:35

ailmanki
BETA Tester
Registered: 08-Jun-12
Posts: 42
Website

Re: Simple script makes me embarrassed

Well this does not produce any error, since the code and all is correct. Its just never executing it, since you need to use exact predefined function names.
Else be sure to check the log files, lua errors are printed there.

I have never used a real debugger for this stuff. What I usually do is use some commands like that, to print something out, or concatenate some variables and print there value.
et.trap_SendServerCommand(clientNum, "print \"Script did run till here big_smile\n\"")

Maybe with a real debugger you would have seen by stepping through that at some point et_ClientCommand gets called, but if you would had noticed then that your function name is different?


b_350_20_692108_381007_FFFFFF_000000.pngb_350_20_692108_381007_FFFFFF_000000.png

Offline

#5 09-Dec-13 22:00:02

Micha
Member
From: Germany
Registered: 11-Feb-13
Posts: 38
Website

Re: Simple script makes me embarrassed

You could use a debug line on your lua. Just erase them or put -- before the line if everything is working well.
et.trap_SendServerCommand(-1,"chat \"Debug 1 \"") --Debug

Server logs print lua errors like ailmanki said (keep in mind that it shows the line number but the error could be caused somewhere else).

Offline

Board footer

Powered by FluxBB