Jump to content

Sleeping until event possible?


Recommended Posts

hi,

i want to halt a script for a unknown amount of time and resume it after a key is pressed.

here is a code snipplet i tried but without success:

global $sleeping = 1 
HotKeySet("+!j", "wakeup")

func sleeping()
    $sleep = 1
    while $sleep > 0
        sleep(1000)
        if $sleeping = 0 Then
            $sleep = 0
        endif
    WEnd
EndFunc

func wakeup()
    $sleeping = 0
EndFunc

if u use this code u get an error message during execusion that $sleeping is not declared when attempting to solve the if statement? i declared it as a global variable to be able to change its value in wakeup(). is $sleeping locked while running the sleeping() function?

HotKeySet is not calling wakeup() when pressing the key combination. do i have to do something else than calling HotKeySet(...) at the beginning of the scipt to get it working?

thanks in advance

Link to comment
Share on other sites

You are not calling function sleeping()

so maybe:

global $sleeping = 1 
HotKeySet("+!j", "wakeup")
sleeping()

func sleeping()
    $sleep = 1
    while $sleep > 0
        sleep(1000)
        if $sleeping = 0 Then
            $sleep = 0
        endif
    WEnd
EndFunc

func wakeup()
    $sleeping = 0
EndFunc
Link to comment
Share on other sites

Your not really clear on what you want. This is my shot in the dark for you.

Global $Paused = 0
HotKeySet("{INSERT}", "Pause")

While 1
    If $Paused = 1 Then
        ;Put your Code here
    
Else
        Sleep(100)
EndIf
WEnd
;;;;;;;;

Func Pause()
    If $Paused = 0 Then
        $Paused = 1
    Else
        $Paused = 0
    EndIf
EndFunc

That will run all the code you want to put in there, when you press the hotkey.

[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...