i have this as part of a script i am writing...
function DataArrival(user, data)
s,e,cmd = strfind(data, "%b<>%s+(%S+)(%S+)")
if (cmd==Prefix..Start) and user.bOperator then
StartTimer()
OnTimer()
end
end
But I want a second command, that when you press it, it stops the timer :S how do i do it...please help
function DataArrival( user, data )
s,e,cmd = strfind( data, "%b<>%s+(%S+)" )
if ( cmd == Prefix..Start ) and ( user.bOperator ) then
StartTimer( iAmountOfMilisecondsBetweenTimerHits )
else
if ( cmd == Prefix..Stop ) and ( user.bOperator ) then
StopTimer()
end
end
end
function OnTimer()
--//insert here what has to be done when timer hits
end
where iAmountOfMilisecondsBetweenTimerHits isn't some inbuild var/const - it's for understadnding purposes... =]
f.e. StarTimer( 60000 ) will fire OnTimer function in 1 minute delays.
Jaras, I think this looks nicer =>
function DataArrival(user, data)
s,e,cmd = strfind(data, "%b<>%s+(%S+)")
if (cmd == Prefix..Start) and user.bOperator then
StartTimer(time) -- seconds x 1000 or minutes x 60000
elseif (cmd == Prefix..Stop) and user.bOperator then
StopTimer()
end
end
function OnTimer()
--//insert here what has to be done when timer hits
end
yup, but i hate using elseif and i always put condisions in brackets when there are more then one to make code look nicer :D
how about making cmd a local?
@jaras: your way uses 2 lua commands else and if, so elseif is always faster.
above 4 if/elseif's i advice 2 use a table.
plop