Msypon Posted January 8, 2013 Posted January 8, 2013 Whats wrong? i want to allow only these commands to output on chat [lua]commands = { 'hi', 'oh' } addEventHandler('onPlayerCommand',root,function(cmd) if cmd == commands[cmd] then outputChatBox('passed') end end )
manve1 Posted January 8, 2013 Posted January 8, 2013 (edited) script doesn't make any sense at all. as even table is wrong: Table should look like this: local commands = { {'hi'} = true, {'oh'} = true; }; The script didn't define 'cmd' appropriately, it defined it as a function command (( That's what i get mostly when i don't define it appropriately )) P.S. Not sure about the rest of script as i am tired Edited January 9, 2013 by Guest
Anderl Posted January 8, 2013 Posted January 8, 2013 How is the table wrong? The table has no syntax error. @Msypon, the script isn't working because what you are doing in the if statement is comparing "cmd" string with the called index from 'commands' table but your table is number-indexed. The table below is how it should be: local g_pCommands = { [ "hi" ] = true, [ "oh" ] = true; }; You should also check if there is an index with same string chars as "cmd", not check if "cmd" is equal to "commands[cmd]": if ( commands[cmd] ) then By the way, use local variables the more you can.
MR.S3D Posted January 8, 2013 Posted January 8, 2013 commands = { ['hi'] = true, ['oh'] = true, } addEventHandler('onPlayerCommand',root, function(cmd) if commands[cmd] then outputChatBox('passed') end end )
GhostXoP Posted January 8, 2013 Posted January 8, 2013 script doesn't make any sense at all Different Conventions do exist.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now