More that one time in a script
 

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

More that one time in a script

Started by OpiumVolage, 10 October, 2003, 23:45:54

Previous topic - Next topic

0 Members and 17 Guests are viewing this topic.

OpiumVolage

-- MultiTimer by OpiumVolage (19/06/2003)
-- Ideas taken from tezlo's retrobot

tabTimers = {n=0}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

TmrFreq = 1*Min

function tmrtest()
--	SendToAll( "PtokaX", users.n )
end

function Main()
	RegTimer(tmrtest, 1*Min)
	SetTimer(TmrFreq)
	StartTimer()
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

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

pHaTTy

Resistance is futile!

NightLitch

I must be dumb or I can't get it working with multi timers...

Plz give me an example off this...

I want one timer on 60000 and one on 20000 how would this look...

I am not so familiar with timers so plz help me understand...

Best Show'n with some examples....

/NightLitch
//NL

OpiumVolage

Here you are 60000 is One minute and 20000 is 20 seconds:

It's almost the same code, i've just added one function (second timer), and adjusted the timer frequency to someting more adjusted.

-- MultiTimer by OpiumVolage (19/06/2003)
-- Ideas taken from tezlo's retrobot

tabTimers = {n=0}

-- Time Definition
Sec  = 1000
Min  = 60*Sec
Hour = 60*Min
Day  = 24*Hour

TmrFreq = 20*Sec

function tmrone()
	SendToAll( "PtokaX", "First Timer")
end

function tmrtwo()
	SendToAll( "PtokaX", "Second Timer" )
end

function Main()
	RegTimer(tmrone, 1*Min)
	RegTimer(tmrtwo, 20*Sec)
	SetTimer(TmrFreq)
	StartTimer()
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

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

NightLitch

ThX OpiumVolage but how would this be done:

function Main()
	frmHub:RegBot(BotName)
	SetTimer(60000)
	StartTimer()
end

function OnTimer()
	for key, value in tabAdvert do
		if (tabAdvert[key].iClock > clock()+60) then
			tabAdvert[key]=nil
		end
	end
end

It's taken from Lucifer 6.6.6 I want to add this to my script so how would this look in your time-script...

Regards / NightLitch
//NL

NightLitch

No Need to Help I fixed it myself I think...

/NightLitch
//NL

shipiz

#6
I get:

No syntax errors in script file timer.lua
Syntax error: attempt to perform arithmetic on global `Hub' (a nil value)
stack traceback:
   1:  method `func' at line 17 [file `F:\hub\scripts\timer.lua']
   2:  function `OnTimer' at line 31 [file `F:\hub\scripts\timer.lua']


Madman

function RegTimer(F,Interval,Name)
	local tmpTrig = Interval / TmrFreq
	assert(Interval >= TmrFreq, "RegTimer(): Please Adjust TmrFreq")
	local Timer = {n=0}
	local Hit = nil
	for I in ipairs(tabTimers) do
		if tabTimers[I].Name == Name then
			Hit = 1
		end
	end
	if Hit then
		-- Don't add...
	else
		Timer.Name = Name
		Timer.Func = F
		Timer.Trig = tmpTrig
		Timer.count=1
		table.insert(tabTimers, Timer)
	end
end

function RemoveTimer(Name)
	local count = 0
	for I in ipairs(tabTimers) do
		count = count+1
		if string.find(tabTimers[I].Name, Name) then
			Timer2Remove = count
			break
		end
	end
	table.remove(tabTimers, Timer2Remove)
end


Updated the code...
Now it can't add the same timer twice, and added a function to remover timers...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk