Jump to content

Global Variable And Func While Loop

Recommended Posts

I'm trying to think of a good user-defined function for pausing, and I cannot figure out why the following code fails this task. Once paused, I cannot unpase.....

Global $PAUSE_STATE = 0 ;1 = pause, 0 = not paused

HotKeySet("{PAUSE}", "PauseScript")
HotKeySet("{ESC}", "UnPauseScript")  

; body of script would go here

Func PauseScript()
   while $PAUSE_STATE  ;this is global, isn't it?

Func UnPauseScript()
   Exit ;for debugging purposes to test unpause function
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to post
Share on other sites
  • Developers

tried this before as well... but assumed you could only have 1 hotkey activated at one time...

Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
Live for the present,
Dream of the future,
Learn from the past.

Link to post
Share on other sites
  • Administrators

I'd cut and pasted the code that handles Adlibs and it had the same check to prevent adlib firing whilst adlib was running :whistle:. No wonder everyone said they couldn't get a puse function working... B)

Link to post
Share on other sites

This seems to work fine:

hotkeyset("{Pause}","Start"); Initially this will start the macro
hotkeyset("!^e","exit1"); this exits the macro from memory

$vsleep = IniRead("config.ini","Delay","delay",1000)
$vjump = IniRead("config.ini","Jump","jump","")

While 1
If $x=1 Then
 send($vjump)  ; send chars defined in INI
 sleep(1)          ; Just incase $vsleep is not defined
 sleep($vsleep) ; sleep amount of msec defined in INI

Func Stop()
hotkeyset("{Pause}","Start"); changes to make Pause start macro

Func Start()
hotkeyset("{Pause}","Stop"); changes to make Pause stop macro

Func exit1()

Larry wrote something like this that works great as well:

AdlibEnable("pause"); this keeps running at all times till you exit.

HotKeySet("{pause}","pauseset"); uses the pause key to change the value of $Pause
$Pause = -1

While 1
 send("4"); this sends the number 4 key to the active program.
 sleep(1000) ; sleep for 1 second before repeating

Func pauseset()
   $Pause = $Pause * -1

Func pause()
   While $Pause = -1

It seems more that you can only have one function at one time, kinda of a funtion in a function loop. The adlib is a good way to circumvent it because autoit seems to stop what it is doing and check this. (correct me if I am wrong.) So you can see that both aproaches use the um..features of AutoIt to thier advantage. I tried to keep it simple. The adlib function works better because it can pause a script at any point, where the changing of hotkey aproach stops at the next breakpoint.

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...