local commandtable={
["invite"]= invite(user,data,env,"temp"),
["remove"]=removeopchat(user,data,env),
["perminvite"]=invite(user,data,env,"perm"),
-- etc etc
}
The question is:
if commandtable[cmd] then return commandtable[cmd] end
why does not work properly? (executes ALL commands)
can that be a prob that i dont return 1 inside my functions? or what?
help me i have 108 commands and im vomiting of elseif ;)
just asking because this script (http://board.univ-angers.fr/thread.php?threadid=3101&boardid=11&sid=88c0faa2eab0241a7d7fc02bf856f16d&page=1#6) works.
**Edit**
I used to use this;if cmd and commandtable[cmd] then return commandtable[cmd](arg1, arg2, arg3, arg4) end
And another tip, i got from RabidWombat; use reference in commandtable instead,
like commandtable={
["invite"]= invite,
["remove"]=removeopchat,
["perminvite"]=invite,
-- etc etc
}
Note; load the functions before the commandtable, so the table knows what to reference to.
I've used this in GeoIP-script.
OK, but as i mentioned, diff funcions use diff variables. So if i use commandtable[cmd](var1,var2) then it will give a nil error when i link 2 a function(var1,var2,var3)...
Why parse only two arguments?
Try to parse as many as the max. arg's needed for a function.
If a function need less, than it choose the first args given and skipping the rest.
commandtable[cmd](...)
this should work on any amount of arguments.
plop
QuoteOriginally posted by plop
commandtable[cmd](...)
this should work on any amount of arguments.
plop
[customcmd5]=showtextfile(user,customtext5,customcmdlev5,env),
---------------- custom add/show/del command shit
-- guestbook stuff
[gbcmd1]=showshit(user,entries,gbname,gbfile,levgbcmd1,env),
-- (user,container,wtf,file),
[gbcmd2]=addshit(user,data,entries,gbfile,levgbcmd2,env),
-- (user,data,container,file),
[gbcmd3]=delshit(user,data,entries,gbfile,gbname,levgbcmd3,env),
what the hell should be done with this then? (altho thx 4 help)
*** EDIT ***
what about dostring(commandtable[cmd]) ?
(i know, then values should be strings)
Quotewhat about dostring(commandtable[cmd]) ?
(i know, then values should be strings)
does not work, do you have any other ideas?
!me always helps, will he get helped out once? :baby:
dunno if this helps
function dummy1(arg1, arg2, arg3)
bla bla bla
end
dummy2 = function(arg1,arg2)
bla bla bla
end
Funcs = {}
Funcs.trigger1 = dummy1
Funcs.trigger2 = dummy2
-- to call
local trig
if Funcs[trig] then
-- execute function
Funcs[trig](arg1,arg2,arg3)
end