Delay script
Posted: Sun Jan 06, 2013 3:54 am
Hi folks,
First post here, hello you you all.
I've been doing some scripting on a custom dungeon and as part of it I needed a delay. As I couldn't find a way to do it within the existing tools I wrote this simple delay script. I thought I would share it here in case it is useful.
This delay script calls a specific function after a specified period of time (in seconds). I named it "delay". The limitation of this delay script is that it will not return you to the function that called the delay (I tried to work on that, but as I couldn't use the debug.getinfo trackback I couldn't do it).
I've only been programming lua since tuesday when i first opened the editor (and I am not an IT pro), so if any of the experts on here can see a more efficient way of doing it, or know how to trackback to calling function without using debug tools, please don't hesitate to speak up!
Syntax for calling the delay:
delay.length(<seconds>,"<script to call after delay>","<function to call after delay>")
e.g. delay.length(20,"script1","function1")
(the script and function name must be in "" marks - if you call the script something other than delay the call will be different and need to be changed)
Script code:
Regards,
Shane
First post here, hello you you all.
I've been doing some scripting on a custom dungeon and as part of it I needed a delay. As I couldn't find a way to do it within the existing tools I wrote this simple delay script. I thought I would share it here in case it is useful.
This delay script calls a specific function after a specified period of time (in seconds). I named it "delay". The limitation of this delay script is that it will not return you to the function that called the delay (I tried to work on that, but as I couldn't use the debug.getinfo trackback I couldn't do it).
I've only been programming lua since tuesday when i first opened the editor (and I am not an IT pro), so if any of the experts on here can see a more efficient way of doing it, or know how to trackback to calling function without using debug tools, please don't hesitate to speak up!
Syntax for calling the delay:
delay.length(<seconds>,"<script to call after delay>","<function to call after delay>")
e.g. delay.length(20,"script1","function1")
(the script and function name must be in "" marks - if you call the script something other than delay the call will be different and need to be changed)
Script code:
Code: Select all
function length(delay_length,target_script,target_function)
local dl = delay_length
local ts = target_script
local tf = target_function
if findEntity("delay_unique_number") == nil
then
spawn("counter", party.level,0,0,0,"delay_unique_number")
:setValue(1)
else
delay_unique_number:increment()
end
local timername = ("timer_counter_" .. delay_unique_number:getValue())
spawn("timer",party.level,0,0,0,timername)
:addConnector("activate", ts, tf)
:addConnector("activate", timername, "destroy")
:setTimerInterval(dl)
:activate()
end
Shane