Using Multiple timers, want to selectively restart the timers
 

Using Multiple timers, want to selectively restart the timers

Started by Stravides, 27 February, 2004, 23:50:33

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Stravides

ok, I'm using the script timers from this here forum for multiple timere and also tryign to integrate wiseguy variant into my bot.. any suggestions ?

Below is a fragment of the code I'm using

the multiple timers scripts are:
-- Time Definition
Sec	= 1000
Min	= 60*Sec
Hour 	= 60*Min
Day	= 24*Hour
Week	= 7*Day

TmrFreq = 10*Sec
tabTimers = {n=0}

function main()
	RegTimer(ForumTimer, 4*Hour)
	RegTimer(QuizTimer, 3*Hour)
 	RegTimer(RandomTimerMsg, 1*Hour)
 	RegTimer(WiseGuyTimerMsg, 2*Hour) -- this is the one I want to restart on demand...
	RegTimer(CheckShare, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()
end 

function ForumTimer()
--	func goes here
end

function QuizTimer()
--	func goes here
end

function CheckShare()
--	func goes here
end

function RandomTimerMsg()
--	func goes here
end

function WiseGuyTimerMsg() 
--	func goes here
--	need to stop and start only this timer, but norm would use
	StopTimer()

	StartTimer() 
end 

function RegTimer(f, Interval)
	local tmpTrig = Interval / TmrFreq
	assert(Interval >= TmrFreq , "RegTimer(): Please Adjust TmrFreq")
	local Timer = {n=0}
	Timer.func=f
	Timer.trig=tmpTrig
	Timer.count=1
	tinsert(tabTimers, Timer)
end

function OnTimer()
	for i=1, getn(tabTimers) do
		tabTimers[i].count = tabTimers[i].count + 1
		if tabTimers[i].count > tabTimers[i].trig then
			tabTimers[i].count=1
			tabTimers[i]:func()
		end
	end
end
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

nErBoS

You want to stop the timer with another timer or with a command ???
--## nErBoS Spot ##--

Stravides

#2
I wanna be able to say anywhere in the code

stop this timer
or restart this timer,  but only one ..

ie
if (cmd=="!quiet") then 
					quiet = "true" 
					talk = "notallow" 
					StopTimer() 
					user:SendPM(botname,"Ok,...I'll be quiet now... :s") 
				end 
				if (cmd=="!talk") then 
					talk = "allow" 
					quiet = "false" 
					WaitingForAnswerAfterQuiet = "false" 
					WaitingForAnswerMorning = "false" 
					WaitingForAnswerEvening = "false" 
					StartTimer() 
					user:SendPM(botname, "Ahh... i'm back :)") 
				end
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

nErBoS

Is this what you want ???

time = 0

---in Data Arrival
if (cmd=="!stop") then 
time = 0
end 
if (cmd=="!start") then 
time = 1
end 


---- In the function WiseGuy

if (time == 0 or time == nil) then
StopTimer()
else
StartTimer()
end
--## nErBoS Spot ##--

Stravides

#4
the way the bot works if ya look at the original post in func main it loads 5 timers

   RegTimer(ForumTimer, 4*Hour)
   RegTimer(QuizTimer, 3*Hour)
    RegTimer(RandomTimerMsg, 1*Hour)
    RegTimer(WiseGuyTimerMsg, 2*Hour)    RegTimer(CheckShare, 1*Min)

I just want the wiseguy timer to be stopped and started, but by using StopTimer() or StartTimer() will that not reset all timers ?
I think the key is in here... but dont completely understand it...
function RegTimer(f, Interval)
	local tmpTrig = Interval / TmrFreq
	assert(Interval >= TmrFreq , "RegTimer(): Please Adjust TmrFreq")
	local Timer = {n=0}
	Timer.func=f
	Timer.trig=tmpTrig
	Timer.count=1
	tinsert(tabTimers, Timer)
end

function OnTimer()
	for i=1, getn(tabTimers) do
		tabTimers[i].count = tabTimers[i].count + 1
		if tabTimers[i].count > tabTimers[i].trig then
			tabTimers[i].count=1
			tabTimers[i]:func()
		end
	end
end
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

Stravides

#5
Do I take it from this that the timer table is composed of 3 tables func, trig and count ?

So for :
  RegTimer(ForumTimer, 4*Hour)
  RegTimer(QuizTimer, 3*Hour)
  RegTimer(RandomTimerMsg, 1*Hour)
  RegTimer(WiseGuyTimerMsg, 2*Hour)
  RegTimer(CheckShare, 1*Min)

TabTimers should have in it

   Timer.func=ForumTimer   
   Timer.trig=4*Hour/10*Sec
   Timer.count=1

   Timer.func=QuizTimer   
   Timer.trig=3*Hour/10*Sec
   Timer.count=1

   Timer.func=RandomTimerMsg   
   Timer.trig=1*Hour/10*Sec
   Timer.count=1

   Timer.func=WiseGuyTimerMsg   
   Timer.trig=4*Hour/10*Sec
   Timer.count=1

   Timer.func=CheckShare   
   Timer.trig=1*Min/10*Sec
   Timer.count=1

is this as clear as mus as it is to me :S
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

nErBoS

#6
I think this will do...

if (time == 0 or time == nil) then
           StopTimer()
	RegTimer(ForumTimer, 4*Hour)
	RegTimer(QuizTimer, 3*Hour)
 	RegTimer(RandomTimerMsg, 1*Hour)
	RegTimer(CheckShare, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()
else
	RegTimer(ForumTimer, 4*Hour)
	RegTimer(QuizTimer, 3*Hour)
 	RegTimer(RandomTimerMsg, 1*Hour)
 	RegTimer(WiseGuyTimerMsg, 2*Hour) 
	RegTimer(CheckShare, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()

end
--## nErBoS Spot ##--

kepp

yea, don't use StopTimer() that will stop all timers

i have no idea how to stop any of those...
let's wait and see what the author has to say about this :)
Guarding    

Stravides

QuoteOriginally posted by nErBoS
I think this will do...

if (time == 0 or time == nil) then
           StopTimer()
	RegTimer(ForumTimer, 4*Hour)
	RegTimer(QuizTimer, 3*Hour)
 	RegTimer(RandomTimerMsg, 1*Hour)
	RegTimer(CheckShare, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()
else
	RegTimer(ForumTimer, 4*Hour)
	RegTimer(QuizTimer, 3*Hour)
 	RegTimer(RandomTimerMsg, 1*Hour)
 	RegTimer(WiseGuyTimerMsg, 2*Hour) 
	RegTimer(CheckShare, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()

end

this again will restart all the timers... basically the wiseguy timer looks for a keypress in main chat if it receves a comment it will reset the timer..
but I want the general advert to go out as timed , ie never reset. :)  Never easy is it :D
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

NightLitch

Well why not just putting triggers that will start them, or not start them but doing the function inside the timer.

ex:

WiseGuyTrig=0

function ForumTimer()
--	func goes here
end

function QuizTimer()
--	func goes here
end

function CheckShare()
--	func goes here
end

function RandomTimerMsg()
--	func goes here
end

function WiseGuyTimerMsg()
   if WiseGuyTrig==1 then
--	func goes here
   end
end

and in datarrival:

---in Data Arrival
if (cmd=="!start") then  -- and adding an arg. in !start then you can use it like this: !start wiseguy, !start cshare etc.
WiseGuyTrig=1
end 
if (cmd=="!stop") then  -- same goes here...
WiseGuyTrig=0
end 


---- In the function WiseGuy

if (time == 0 or time == nil) then
//NL

OpiumVolage

QuoteOriginally posted by Stravides
Do I take it from this that the timer table is composed of 3 tables func, trig and count ?

So for :
  RegTimer(ForumTimer, 4*Hour)

   Timer.func=ForumTimer   
   Timer.trig=4*Hour/10*Sec
   Timer.count=1


You can use tremove to stop the timer (removing a timer from the table: timer[n]

And timer.count=1 to reset a timer.

Stravides

thanks a lot, will try that and see how I get on..
Stravides
For RPG Books, Mp3 & Videos
We host trivia  and the ever failing Smeagolbot

SMF spam blocked by CleanTalk