Functions and tables
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Functions and tables

Started by bastya_elvtars, 12 November, 2004, 02:35:09

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

bastya_elvtars

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  works.
Everything could have been anything else and it would have just as much meaning.

VidFamne

#1
**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.

bastya_elvtars

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)...
Everything could have been anything else and it would have just as much meaning.

VidFamne

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.

plop

commandtable[cmd](...)
this should work on any amount of arguments.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

bastya_elvtars

#5
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)
Everything could have been anything else and it would have just as much meaning.

bastya_elvtars

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:
Everything could have been anything else and it would have just as much meaning.

chill

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

SMF spam blocked by CleanTalk