PtokaX forum

Development Section => Your Developing Problems => Topic started by: bastya_elvtars on 12 November, 2004, 02:35:09

Title: Functions and tables
Post by: bastya_elvtars on 12 November, 2004, 02:35:09
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.
Title:
Post by: VidFamne on 12 November, 2004, 10:54:04
**Edit**
I used to use this;if cmd and commandtable[cmd] then return commandtable[cmd](arg1, arg2, arg3, arg4) endAnd 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.
Title:
Post by: bastya_elvtars on 12 November, 2004, 14:37:13
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)...
Title:
Post by: VidFamne on 12 November, 2004, 22:25:26
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.
Title:
Post by: plop on 13 November, 2004, 00:16:55
commandtable[cmd](...)
this should work on any amount of arguments.

plop
Title:
Post by: bastya_elvtars on 14 November, 2004, 21:07:46
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)
Title:
Post by: bastya_elvtars on 22 November, 2004, 02:19:11
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:
Title:
Post by: chill on 22 November, 2004, 10:28:55
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