Launching a script, stopping a timer
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Launching a script, stopping a timer
HI guys, I'm having a question about the timer.
It seems it pauzes if I let the timer loop ( deactivate then activate)
IS there maybe another way so it won't pauzes for a sec once the countdown/timer starts at 0 or 1 again?
Now its like 1,2,3,4 pauzes...1,2,3,4, etc etc.
Thanks in advanced.
It seems it pauzes if I let the timer loop ( deactivate then activate)
IS there maybe another way so it won't pauzes for a sec once the countdown/timer starts at 0 or 1 again?
Now its like 1,2,3,4 pauzes...1,2,3,4, etc etc.
Thanks in advanced.
Re: Launching a script, stopping a timer
A one second pause sounds like it's just ticking down to zero; as expected... Is there a specific reason that you don't subtract one second from the timerValue?
** I suppose that you could setup a counter and script to decrement the counter and check the value; quitting arbitrarily whenever you like... You would run the script on a timer set to 1 or just less than 1, and that timer should always be spawned on the same level as the party... and respawned if they change levels.
** I suppose that you could setup a counter and script to decrement the counter and check the value; quitting arbitrarily whenever you like... You would run the script on a timer set to 1 or just less than 1, and that timer should always be spawned on the same level as the party... and respawned if they change levels.
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Launching a script, stopping a timer
Is is this as simple as: ? Meaning it starts at 1, the 1 value?
Im not sure how to script it in the lua though.
i got something like this:
An unchanged timer is activated by a plate, and the timer is connected to this script.
Edit: This 1 supose to start on value 2, the other script starts at value 1 ( so it switching from script 1 to 2 over and over)
SpoilerShow
"timer_1 = 1"
Im not sure how to script it in the lua though.
i got something like this:
SpoilerShow
timecount = 1
function bassline21()
if timecount == 2 then
spawn("paars_light", 5, 29, 12, 3, "paars_kick22")
elseif timecount == 3 then
paars_kick22:destroy()
timecount = 1
return
end
timecount = timecount + 1
end
function bassline21()
if timecount == 2 then
spawn("paars_light", 5, 29, 12, 3, "paars_kick22")
elseif timecount == 3 then
paars_kick22:destroy()
timecount = 1
return
end
timecount = timecount + 1
end
Edit: This 1 supose to start on value 2, the other script starts at value 1 ( so it switching from script 1 to 2 over and over)
Re: Launching a script, stopping a timer
What is it ~exactly, that you are attempting to do with this timer?
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Launching a script, stopping a timer
HI Isaac,Isaac wrote:What is it ~exactly, that you are attempting to do with this timer?
First of all thanks for your intrest in this.
Well, as i said it goes 1,2,3,4 .....1,2,3,4 for instance. I do not want it. It must be a steady 1,2,3,4,1,2,3,4. No breaks in it. I got no idea what I did wrong in this script ( or set timer?)
Greetz
Edit: I you try this:
SpoilerShow
timecount = 1
function bassline21()
if timecount == 1 then()
door_1:open
elseif timecount == 2 then
door1_1:close()
timecount = 1
return
end
timecount = timecount + 1
end
function bassline21()
if timecount == 1 then()
door_1:open
elseif timecount == 2 then
door1_1:close()
timecount = 1
return
end
timecount = timecount + 1
end
Re: Launching a script, stopping a timer
Try this out. Place this code in a script object named 'customTimer'. It creates a counter that will smoothly cycle from 1 to 4, and then to 1 again.
There is space marked for your own code instructions, but you can just as well check the counter value from any script you wish.
To keep the timer running smoothly, the code offers two ways to respawn the timer on the same level as the party; timers slow down when they are not on the current level. To use this [optional], either place a hidden pressure plate on any cell with stairs, and connect the plates to this script; or call the oneTwoThreeFour() function from a script using: timerScript.oneTwoThreeFour(self, "respawn") , this will create a new timer on the current level.
Use either method, or both where ever the party might change floor levels.
*When you get tired of console spam, erase or comment the print statement.
https://www.dropbox.com/s/39i2w3pvpha1z17/1234.zip
There is space marked for your own code instructions, but you can just as well check the counter value from any script you wish.
To keep the timer running smoothly, the code offers two ways to respawn the timer on the same level as the party; timers slow down when they are not on the current level. To use this [optional], either place a hidden pressure plate on any cell with stairs, and connect the plates to this script; or call the oneTwoThreeFour() function from a script using: timerScript.oneTwoThreeFour(self, "respawn") , this will create a new timer on the current level.
Use either method, or both where ever the party might change floor levels.
*When you get tired of console spam, erase or comment the print statement.
Code: Select all
hidden_counter = -1
spawn("counter", party.level,1,1,1, "timecount"):setValue(0)
spawn("timer", party.level,1,1,1, "customTimer")
:setTimerInterval(1)
:addConnector("activate","timerScript", "oneTwoThreeFour")
:activate()
function oneTwoThreeFour(caller, command)
if command == "restart" then
if not findEntity("timecount") then spawn("counter", party.level,1,1,1, "timecount"):setValue(0) end
if not findEntity("customTimer") then spawn("timer", party.level,1,1,1, "customTimer")
:setTimerInterval(1)
:addConnector("activate","timerScript", "oneTwoThreeFour")
:activate()
else
customTimer:activate()
end
end
if command == "stop" then customTimer:deactivate() end
if command == "respawn" or caller ~= nil and caller.name == "pressure_plate_hidden" then
_safeDestroy(customTimer)
local condition = caller.level
if command == "respawn" then condition = party.level
end
spawn("timer", condition,1,1,1, "customTimer")
:setTimerInterval(1)
:addConnector("activate","timerScript", "oneTwoThreeFour")
:activate()
print("timer respawned to level ", customTimer.level)
end
hidden_counter = hidden_counter + 1
timecount:setValue(hidden_counter % 4 +1)
-- Put your code below --
--The value to check is timecount:getValue()
hudPrint(tostring(timecount:getValue()))
--You can of course erase these three lines.
-- Put your code above --
end
oneTwoThreeFour()
function _safeDestroy(target)
if findEntity(target.id) then
target:destroy()
return true
end
return false
end
-
- Posts: 275
- Joined: Sat Jun 16, 2012 5:32 am
Re: Launching a script, stopping a timer
Omg.
It was as simple as removing the "return" command.
The return command, returned somehwere making a delay in the timer.
so now its:
Works perfectly now. now its 1.2.1.2.1.2.1.2. etc.
Thanks alot for you help. I will try you script also mate.
Ps: edit: I told the script also the timecount = timecount + 1.. was also a bad. Should of been zero, so it truely resets.
Again thanks alot isaac. Love ya.
It was as simple as removing the "return" command.
The return command, returned somehwere making a delay in the timer.
so now its:
SpoilerShow
timecount = 0
function bassline51()
if timecount == 1 then
spawn("paars_light", 5, 25, 12, 3, "paars_kick62")
end
if timecount == 2 then
paars_kick62:destroy()
timecount = 0
end
timecount = timecount + 1
end
function bassline51()
if timecount == 1 then
spawn("paars_light", 5, 25, 12, 3, "paars_kick62")
end
if timecount == 2 then
paars_kick62:destroy()
timecount = 0
end
timecount = timecount + 1
end
Thanks alot for you help. I will try you script also mate.
Ps: edit: I told the script also the timecount = timecount + 1.. was also a bad. Should of been zero, so it truely resets.
Again thanks alot isaac. Love ya.
-
- Posts: 7
- Joined: Mon Jan 19, 2015 10:46 am
Re: Launching a script at other level
Hello guys,
I am trying to make it easier by creating one script on level 1
which specific alcoves call, such alcove is on every other level (up to 12)
but I noticed that when calling script put with editor on different level other is the calling entitiy,
all the processing is really slow, about 10 times
when both alcove and script are on same level - no delays.
is there any trick around this?
thank you
I am trying to make it easier by creating one script on level 1
which specific alcoves call, such alcove is on every other level (up to 12)
but I noticed that when calling script put with editor on different level other is the calling entitiy,
all the processing is really slow, about 10 times
when both alcove and script are on same level - no delays.
is there any trick around this?
thank you
Re: Launching a script, stopping a timer
Objects that are not on the party's level update slower than objects that are on the party's level. This means that off-level timers run much slower. If you want a timer that runs at the same speed regardless of the party's level, attach a TimerComponent to the party instead of using a "timer" object. You may also want to consider using delayedCall() instead.
edit: oops, didn't notice I'm in the Grimrock 1 subforum. For multi-level timers in Grimrock 1 you should look at the LoG scripting framework.
edit: oops, didn't notice I'm in the Grimrock 1 subforum. For multi-level timers in Grimrock 1 you should look at the LoG scripting framework.
Last edited by minmay on Thu Jan 22, 2015 6:16 pm, edited 1 time in total.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
-
- Posts: 7
- Joined: Mon Jan 19, 2015 10:46 am
Re: Launching a script, stopping a timer
Thank you minmay,minmay wrote:Objects that are not on the party's level update slower than objects that are on the party's level. This means that off-level timers run much slower. If you want a timer that runs at the same speed regardless of the party's level, attach a TimerComponent to the party instead of using a "timer" object. You may also want to consider using delayedCall() instead.
as usually I found the solution 5 minutes after asking )
now I still use one script at level one but spawn timers at party entrance level (create teleporter) and party destination level of the teleporter (destory teleporter)
the delayedCall looks great, I might use that instead in updated version.