PLEEEEEEASE HELP ME
 

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

PLEEEEEEASE HELP ME

Started by Exile, 08 February, 2005, 19:39:04

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Exile

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


Jaras

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.

blackwings

#2
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


Jaras

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

plop

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
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 <----<<

SMF spam blocked by CleanTalk