Page 1 of 2
Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 1:00 pm
by DrKojak
Is it possible to script triggers on a timer in real-time seconds?
Or is it possible to accurately measure/divide the timer asset's 'timerintervals' into real-time seconds? the timer assets in the editor seem to be about 0.3 to 0.4 of a second each and i can't successfully time a load of scripts to play out at near-precisely timed intervals (timed to music)
What script would i need to write to, for example.
start a separate script at 10 seconds after the party steps onto a floor trigger
start a separate script at 30 seconds after
start a separate script at 32 seconds after
start a separate script at 34 seconds after
start a separate script at 36 seconds after
start a separate script at 70 seconds after
etc and so forth
this is going to go on for 6-7 minutes of activating trap sequences and spawning in enemies in-case the party is too slow to defeat the boss quickly, who will be teleported in at 70 seconds.
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 1:37 pm
by Vice Dellos
connect a timer with triggerOnStart ticked and interval 1 (1 second) onto a script with something like this
Code: Select all
time = 0
function eventCaller()
time = time + 1
if time == 10 then
print("you have been playing for 10 seconds")
elseif time == 30 then
print("you have been playing for 30 seconds")
elseif time == 32 then
print("you have been playing for 32 seconds")
elseif time == 34 then
print("you have been playing for 34 seconds")
end
end
then enter what you want to happen in each elseifs (where it says print now)
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 1:52 pm
by DrKojak
Vice Dellos wrote:connect a timer with triggerOnStart ticked and interval 1 (1 second) onto a script with something like this
Code: Select all
time = 0
function eventCaller()
time = time + 1
if time == 10 then
print("you have been playing for 10 seconds")
elseif time == 30 then
print("you have been playing for 30 seconds")
elseif time == 32 then
print("you have been playing for 32 seconds")
elseif time == 34 then
print("you have been playing for 34 seconds")
end
end
then enter what you want to happen in each elseifs (where it says print now)
ah, thanks man! the timer seems to be rather accurate per second
going to be lots of work syncing traps, spawning, enabling/disabling torches and lights to this song but hopefully it will be awesome.
https://www.youtube.com/watch?v=KAUBTAhp3n8
only thing i can't seem to get right is i want to start the timer when a trigger is stepped on, however no matter how i set it up it starts when the game or test has started...
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 2:06 pm
by Vice Dellos
add a line to the script (before the function so it gets done on startup) that disables the timer
something like:
works i believe (where "timer_1" is the ID of the timer you are using)
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 2:16 pm
by DrKojak
Vice Dellos wrote:
something like:
works i believe (where "timer_1" is the ID of the timer you are using)
thanks man, i got it working, added a floor trigger where the player spawns in to the area that stops the timer immediately in a script, then added a trigger that starts the timer and begins running the script you shared.
thanks man!
time to let my masochistic labor of love begin!
will probably upload a video of the test once it's completed
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 2:18 pm
by antti
Another technique you can use in LoG2 are delayedCalls. The syntax is delayedCall(scriptEntityId, delayInSeconds, functionName). Here's an example:
Code: Select all
function startSequence()
print("Sequence started...")
delayedCall(self.go.id, 1.5, "firstEvent")
delayedCall(self.go.id, 10, "secondEvent")
end
function firstEvent()
print("This script is run 1.5 seconds after the start.")
end
function secondEvent()
print("This is printed 10 seconds after start.")
end
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 2:27 pm
by DrKojak
antti wrote:Another technique you can use in LoG2 are delayedCalls. The syntax is delayedCall(scriptEntityId, delayInSeconds, functionName). Here's an example:
Code: Select all
function startSequence()
print("Sequence started...")
delayedCall(self.go.id, 1.5, "firstEvent")
delayedCall(self.go.id, 10, "secondEvent")
end
function firstEvent()
print("This script is run 1.5 seconds after the start.")
end
function secondEvent()
print("This is printed 10 seconds after start.")
end
this one may be even better to use. thanks guys!
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 3:59 pm
by Lark
This is utterly FANTASTIC! I can quit spawning and destroying timers to accomplish such sequencing now that
delayedCall is known. Just when I think it can't get any better... Thank you Antti!! Well, please excuse me now, I have to go rip out a bunch of timer code. Utterly fantastic game!! -Lark
Re: Scripting time in real-time seconds
Posted: Thu Oct 30, 2014 4:03 pm
by NutJob
antti wrote:Another technique you can use in LoG2 are delayedCalls. The syntax is delayedCall(scriptEntityId, delayInSeconds, functionName). Here's an example:
Code: Select all
function startSequence()
print("Sequence started...")
delayedCall(self.go.id, 1.5, "firstEvent")
delayedCall(self.go.id, 10, "secondEvent")
end
function firstEvent()
print("This script is run 1.5 seconds after the start.")
end
function secondEvent()
print("This is printed 10 seconds after start.")
end
You just resurrected a scripting idea. Please keep saying stuff! ~laughs~
Thanks!
Edit: between delayedCall, getOrdinal, and setWorldPosition I have to practically rewrite every script I've wrote to-date. Oh well,
somehow it's fun for me.
Re: Scripting time in real-time seconds
Posted: Fri Oct 31, 2014 11:51 am
by gambit37
Can parameters be passed to functions in a delayedCall?
For example, if I use delayedCall in a loop and pass a parameter based on the value of the loop, I receive an error: "Warning! invalid message: script_entity_5.lightOn(lanterns_levEntrance([e]))"
My code is a loop to turn on all lanterns on the level sequentially with a small delay between each one. "lanterns_levEntrance" is a table already created which contains entity references for all the lanterns on the level. The code works fine if I enable the lights/particles directly (the lines commented out below), but fails with the delayed call.
Code: Select all
function lightsOn()
for e = 1, #lanterns_levEntrance do
--lanterns_levEntrance[e].light:enable()
--lanterns_levEntrance[e].particle:enable()
delayedCall(self.go.id, 0.2, "lightOn(lanterns_levEntrance[e])")
end
end
function lightOn(lightID)
lightID.light:enable()
lightID.particle:enable()
end