Page 2 of 2

Re: Launching a script, stopping a timer

Posted: Mon Sep 01, 2014 10:52 pm
by trancelistic
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.

Re: Launching a script, stopping a timer

Posted: Mon Sep 01, 2014 11:06 pm
by Isaac
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.

Re: Launching a script, stopping a timer

Posted: Tue Sep 02, 2014 2:55 pm
by trancelistic
Is is this as simple as:
SpoilerShow
"timer_1 = 1"
? Meaning it starts at 1, the 1 value?
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
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)

Re: Launching a script, stopping a timer

Posted: Tue Sep 02, 2014 4:47 pm
by Isaac
What is it ~exactly, that you are attempting to do with this timer?

Re: Launching a script, stopping a timer

Posted: Wed Sep 03, 2014 12:07 am
by trancelistic
Isaac wrote:What is it ~exactly, that you are attempting to do with this timer?
HI Isaac,

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
Set it to a timer wich is activate by something. You will notice the door opens and closes right away, then pauzes a sec before it loops again. That I do not want.

Re: Launching a script, stopping a timer

Posted: Wed Sep 03, 2014 3:33 am
by Isaac
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.

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
https://www.dropbox.com/s/39i2w3pvpha1z17/1234.zip

Re: Launching a script, stopping a timer

Posted: Sat Sep 06, 2014 7:18 pm
by trancelistic
Omg.

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
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.

Re: Launching a script at other level

Posted: Wed Jan 21, 2015 10:17 pm
by carlos2000
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

Re: Launching a script, stopping a timer

Posted: Wed Jan 21, 2015 10:31 pm
by minmay
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.

Re: Launching a script, stopping a timer

Posted: Thu Jan 22, 2015 9:55 am
by carlos2000
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.
Thank you minmay,
as usually I found the solution 5 minutes after asking :o)
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.