Page 1 of 2
Timer?
Posted: Mon Oct 27, 2014 5:29 pm
by zeltak
It seems that timer works a little differently than in LoG1. I can't figure out how to use them so that they don't start at the beginning of the game/level.. I tried to use pressure plates so that as pressure plate is activated it starts the timer and when it is deactivated it would stop it. But the timer runs without waiting for the activation? O.o
Is this a bug, or am I missing something?
Re: Timer?
Posted: Mon Oct 27, 2014 6:55 pm
by Lark
Select the timer, then under "Components" you will see a checkbox in front of "timer". Leave it checked for the timer to start immediately, and uncheck it to disable the timer until explicitly started.
Re: Timer?
Posted: Mon Oct 27, 2014 6:57 pm
by zeltak
Thank you! I knew I was missing something.
Re: Timer?
Posted: Fri Nov 07, 2014 7:26 pm
by zeltak
I'll add my question here, as it got buried in that general thread without an answer. If this has been covered in some tutorial or somewhere else, I would appreciate a nudge to right direction.
What does the "currentLevelOnly" do in timers? It seems that timers pause even without it when you're in a different level. And is there a way to make them tick even when you're not in the same level as the timer?
Re: Timer?
Posted: Fri Nov 07, 2014 7:38 pm
by Phitt
zeltak wrote:I'll add my question here, as it got buried in that general thread without an answer. If this has been covered in some tutorial or somewhere else, I would appreciate a nudge to right direction.
What does the "currentLevelOnly" do in timers? It seems that timers pause even without it when you're in a different level. And is there a way to make them tick even when you're not in the same level as the timer?
Timers keep running when the box isn't checked. However they only run in a 1:1 timescale if you are in the same level as the timer. The farther away you are from the timer, the less often it will update. This was done to save performance. If you need accurate timing across levels you can set up a timer in each level that get enabled on entering the level (and disable the previous timer).
Re: Timer?
Posted: Fri Nov 07, 2014 7:45 pm
by zeltak
Alright, thanks. I was trying to figure out a way to accomplish what I wanted. But I didn't think of the easy solution of double timers. Thanks.
Re: Timer?
Posted: Fri Nov 14, 2014 2:58 am
by akroma222
The party can be given Counters and Timers as components...
You can create a party timer with this code that will not suffer timescale issues
(I tested it by printing the counter value each second, and then jumping down a bunch of pits)
Place the definition in your init.lua
Code: Select all
-----------------------------------------------party timer
defineObject{
name = "party",
baseObject = "party",
components = {
{
class = "Counter",
name = "partycounter",
},
{
class = "Timer",
name = "partytimer",
timerInterval = 1.0,
triggerOnStart = true,
onActivate = function(self)
self.go.partycounter:increment()
local v = self.go.partycounter:getValue()
return hudPrint("Time = "..v.."")
end
},
}
}
Re: Timer?
Posted: Sat Nov 15, 2014 12:21 am
by Komag
wow, what an easy perfect solution! any downside?
Re: Timer?
Posted: Sat Nov 15, 2014 12:33 am
by akroma222
I have not found anything yet...
But that has me feeling quite suspicious haha
Going to keep running some more tests today,
I am hoping I can use it as a standardiser for other timers....
or just base timed scripts off the party timer.... hopefully it works as intended!
Re: Timer?
Posted: Sat Nov 15, 2014 3:43 am
by akroma222
Ok, I have made a simple script for giving the party water breathing for 60 seconds
and the timing is based from the partytimer
just add a connector from partytimer to oa spawned waterBreathCounter and set onActivate (partytimer) to decrement waterBreathCounter
add a connector from waterBreathCounter to game script and set onActivate (waterBreathCounter ) to activate the clean up (waterBreathStop())script
I tested this out by connecting a pressure plate to the script and then starting the party on the plate square
that way partytimer (or partycounter) should = waterBreathCounter even if we go jumping down pits for a minute
Code: Select all
function waterBreath()
local t = party.partytimer
local c = findEntity("waterBreathCounter")
if c ~= nil then
c:destroy()
end
t:removeConnector("onActivate", "waterBreathCounter", "decrement")
spawn("counter",party.level,party.x,party.y,party.elevation,party.facing,"waterBreathCounter")
waterBreathCounter.counter:setValue(60)
t:addConnector("onActivate", "waterBreathCounter", "decrement")
waterBreathCounter.counter:addConnector("onActivate", "game", "waterBreathStop")
playSound("generic_spell")
for i = 1, 4, 1 do
if party.party:getChampion(i):isAlive() then
party.party:getChampion(i):setCondition("water_breathing", 10)
end
end
end
function waterBreathStop()
local t = party.partytimer
local c = findEntity("waterBreathCounter")
if c then
c:destroy()
end
t:removeConnector("onActivate", "waterBreathCounter", "decrement")
for i = 1, 4, 1 do
if party.party:getChampion(i):isAlive() then
party.party:getChampion(i):removeCondition("water_breathing")
end
end
hudPrint("this works")
end