[script] Extended timer (setConstant, tickLimit, callbacks)
Re: [script] Extended timer (followParty, tickLimit, callbac
I have an idea. We could create a global timer based on my lightTracker model. This would activate something (a button) with a very small time resolution. So now we have a constant tick at, let's say 1/100s. Then instead of spawning timers, we spawn counters and connect the tick to them with a decrement action. So such a counter of a value of 100 would always activate after 1s no matter where it's placed or where the party is. It could then self-reset and continue until destroyed.
How does that sound?
How does that sound?
Re: [script] Extended timer (followParty, tickLimit, callbac
It sounds like your saying just never use long timers, but always use short ones and if you want a long one then just nest a tick counter in there to do your bidding?Batty wrote:For longer time periods couldn't you do:
The timer on each level calling this function would be set to one second then you don't have the long interval problem.Code: Select all
x = 0 function ticktock(timer) if party.level == timer.level then x = x + 1 end if x == 100 then do this all timers:deactivate() end end
Finished Dungeons - complete mods to play
Re: [script] Extended timer (followParty, tickLimit, callbac
I'm not sure I follow correctly, but in any case I suspect trying to have a constant 1/100 timer running would hurt performanceDiarmuid wrote:I have an idea. We could create a global timer based on my lightTracker model. This would activate something (a button) with a very small time resolution. So now we have a constant tick at, let's say 1/100s. Then instead of spawning timers, we spawn counters and connect the tick to them with a decrement action. So such a counter of a value of 100 would always activate after 1s no matter where it's placed or where the party is. It could then self-reset and continue until destroyed.
How does that sound?
Finished Dungeons - complete mods to play
Re: [script] Extended timer (followParty, tickLimit, callbac
I was suggesting 1/100 just like that... 1/30 or 1/20 could probably be enough. I'll need to try to code an example and see how it goes.
Re: [script] Extended timer (followParty, tickLimit, callbac
I think Battys idea should work, I just have to handle long intervals differently than short ones. Have to try it. Damn, you made me to spend more time on this 

- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: [script] Extended timer (followParty, tickLimit, callbac
Yes, and if you want it to continue on for more long intervals, replace:Komag wrote:It sounds like your saying just never use long timers, but always use short ones and if you want a long one then just nest a tick counter in there to do your bidding?
Code: Select all
all timers:deactivate()
Code: Select all
x = 0
Re: [script] Extended timer (setConstant, tickLimit, callbac
I made it, now it works pretty nicely. Only limitation for constant timers is that if the interval is over 1 second you can't use decimal numbers.
setTimerInterval(1.5) wont work but setTimerInterval(100) or setTimerInterval(0.1) works.
Decimal numbers can be use for "normal" (not constant) timers of course.
Updated the documentation to first post.
setTimerInterval(1.5) wont work but setTimerInterval(100) or setTimerInterval(0.1) works.
Decimal numbers can be use for "normal" (not constant) timers of course.
Updated the documentation to first post.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: [script] Extended timer (setConstant, tickLimit, callbac
I made simple ingame clock with it which uses the compass icon:
Items.lua
to some script entity:
1 second == 1 minute in game time
Items.lua
Code: Select all
cloneObject{
name='clock',
baseObject='compass',
uiName = "Pocket watch",
description='',
onUseItem = function(self)
eTimer = timers:find('clock_timer')
local hours = math.floor((eTimer.tick / 60) % 24)
local minutes = eTimer.tick % 60
if minutes < 10 then minutes = '0'..minutes end
if hours < 10 then hours = '0'..hours end
hudPrint('Time is: '..hours..':'..minutes)
end
}
Code: Select all
function initClock()
party:getChampion(1):insertItem(14,spawn('clock',nil,nil,nil,nil,'clock'))
local clockTimer = timers:create('clock_timer')
clockTimer:setTimerInterval(1)
clockTimer:setConstant()
clockTimer.tick = 7190 -- set the initial time to 23:50
clockTimer:activate()
end
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: [script] Extended timer (setConstant, tickLimit, callbac
I just realized that I can add functions to extended timer dynamically so I changed the clock implementation so that I can access the time easily from anywhere:
Modified example:
Now I can for example get current hour by calling timers:find('clock_timer'):getHours().
Modified example:
Code: Select all
cloneObject{
name='clock',
baseObject='compass',
uiName = "Pocket watch with compass",
description='',
onUseItem = function(self)
local clockTimer = timers:find('clock_timer')
hudPrint('Time is: '..clockTimer:getTime())
end
}
Code: Select all
function initClock()
party:getChampion(1):insertItem(14,spawn('clock',nil,nil,nil,nil,'clock'))
local clockTimer = timers:create('clock_timer')
clockTimer:setTimerInterval(1)
clockTimer:setConstant()
clockTimer.tick = 7190 -- set the initial time to 23:50
clockTimer:activate()
clockTimer.getHours = function(self)
return math.floor((self.tick / 60) % 24)
end
clockTimer.getMinutes = function(self)
return self.tick % 60
end
clockTimer.getTime = function(self)
local minutes = self:getMinutes()
local hours = self:getHours()
if minutes < 10 then minutes = '0'..minutes end
if hours < 10 then hours = '0'..hours end
return hours..':'..minutes
end
end
Last edited by JKos on Sun Nov 25, 2012 11:12 pm, edited 2 times in total.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
- cloneObject viewtopic.php?f=22&t=8450
Re: [script] Extended timer (setConstant, tickLimit, callbac
this is crazy stuff! I guess whenever we get the update with get statistic grime played a lot of this might become moot, but until then it will be pretty useful
Finished Dungeons - complete mods to play