kts.Delay – stun the current actor and also yield for a time
kts.Delay(milliseconds)
This function can be called from within a "callback" such as on_pick_up
, on_walk_over
, etc.
The function will cause the current actor (the creature that triggered the callback) to be "stunned" for the given number of milliseconds.
Then, execution of the callback function will be paused for the same number of milliseconds (as if coroutine.yield
had been called; see also kts.AddTask).
After the stun period has ended, execution of the callback function will resume from where it left off.
No value is returned.
If the parameter is not an integer, then an error is raised.
If there is no current actor (i.e. cxt.actor
is nil) then this is not an error; in this case, execution is still paused for the given number of milliseconds (as if coroutine.yield
had been called), but no creature gets stunned.
Potions are implemented by something like the following:
on_pick_up = function() drink_sound() -- this plays the "potion drinking" sound effect kts.Delay(750) -- stun the knight for 750 milliseconds potion_effect() -- after the stun period ends, apply potion effects to the knight end
Here, it is assumed that drink_sound()
and potion_effect()
are separately defined functions.