How do I script a wait that the player can skip by pressing a key?
From OHRRPGCE-Wiki
(Redirected from Scripts:Skippable wait)
Sometimes you may want a script to wait for a certain amount of time, maybe for a dramatic pause, or to allow a musical flourish to finish, but you also want to allow the impatient player to skip that pause by pressing a key. Here is an example script that implements an interruptible wait.
If you want to skip a whole series of actions, such as a cutscene, an extended article is at Scripts:Skippable cutscene
script, skippable wait, ticks, begin
# Returns true if the wait was cancelled by a keypress.
variable(i)
for(i, 1, ticks) do, begin
wait(1)
if(key is pressed(key:ENTER)) then(exit returning(true))
if(key is pressed(key:SPACE)) then(exit returning(true))
if(key is pressed(key:CTRL)) then(exit returning(true))
if(key is pressed(key:ALT)) then(exit returning(true))
if(key is pressed(key:ESC)) then(exit returning(true))
if(key is pressed(joy:button 1)) then(exit returning(true))
if(key is pressed(joy:button 2)) then(exit returning(true))
end
exit returning(false)
end
And below is a simple wrapper script that allows you to specify the delay in (approximate) seconds rather than in ticks.
script, skippable wait seconds, seconds, begin # Returns true if the wait was cancelled by a keypress. exit returning(key wait(18 * seconds)) end