Scripting time in real-time seconds
Scripting time in real-time seconds
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.
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.
- Vice Dellos
- Posts: 47
- Joined: Thu Feb 28, 2013 12:56 pm
Re: Scripting time in real-time seconds
connect a timer with triggerOnStart ticked and interval 1 (1 second) onto a script with something like this
then enter what you want to happen in each elseifs (where it says print now)
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
Re: Scripting time in real-time seconds
ah, thanks man! the timer seems to be rather accurate per secondVice Dellos wrote:connect a timer with triggerOnStart ticked and interval 1 (1 second) onto a script with something like this
then enter what you want to happen in each elseifs (where it says print now)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
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...
- Vice Dellos
- Posts: 47
- Joined: Thu Feb 28, 2013 12:56 pm
Re: Scripting time in real-time seconds
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)
something like:
Code: Select all
timer_1.timer:stop()
Re: Scripting time in real-time seconds
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.Vice Dellos wrote: something like:works i believe (where "timer_1" is the ID of the timer you are using)Code: Select all
timer_1.timer:stop()
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
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
Steven Seagal of gaming industry
Re: Scripting time in real-time seconds
this one may be even better to use. thanks guys!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
Re: Scripting time in real-time seconds
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
You just resurrected a scripting idea. Please keep saying stuff! ~laughs~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
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
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.
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