Sign in to follow this  
Followers 0
mitchxx

adlib stops working after first run

4 posts in this topic

#1 ·  Posted (edited)

so i have this simple script that works fine execpt for the adlib part. what happens is first run goes great the script pauses as the adlib commands it to do when an error is detected. i press f1 to start it up again it goes through the code again but it does not pause this time it just contiones to run like the adlib function was never there.

HotKeySet("{F6}", "end")
HotKeySet("{F1}", "main")
HotKeySet("{F2}", "pause")
AdlibRegister("checkforerror",1000)

func checkforerror()
PixelSearch(936, 4,978, 32,0xFFD100)
if @error Then
pause()
EndIf
EndFunc
 

func main()
send("§")
nex()
endfunc
 
func nex()
send("§")
tur()
endfunc
 
func tur()
send("§")
nex()
endfunc
 

func pause()
while True
sleep(100)
WEnd
EndFunc
 
 
this is obviously not the exact script but its dumbed down version so you dont have to read the wall of text.  thought it might do aswell since the problem is not the script code there is something wrong the adlib function stopping it from working correctly which i just pasted in.
Edited by mitchxx

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I had the same oroblem in my script from what I can see pause() runs forever and adlibregister never ends then you call main() function but it will run inside adlibregister and adlibregister will never reach a full run only if it ends it will start a second run.

To get adlibregister to run properly you need to allow it to end.

You need to avoid calling your main script in adlib register.

Edited by Raizeno

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

When you press F1 you run main() and then get caught by the recursive calls of nex() and tur() which don't allow checkforerror() to run, to make this check effective you must run it from inside the calls

BTW this recursive thing can readily crash your script if you don't put some kind of stop inside

HotKeySet("{F6}", "end")
HotKeySet("{F1}", "main")
HotKeySet("{F2}", "pause")
;AdlibRegister("checkforerror",1000)

While 1
sleep(10)
Wend

func checkforerror()
PixelSearch(936, 4,978, 32,0xFFD100)
if @error Then
pause()
EndIf
EndFunc
 
func main()
Tooltip("main")
nex()
endfunc
 
func nex()
checkforerror()  ;<<<<<<<
Tooltip("nex")
tur()
endfunc
 
func tur()
Tooltip("tur")
nex()
endfunc
 
func pause()
while True
Tooltip("paused")
sleep(100)
WEnd
EndFunc
Edited by mikell

Share this post


Link to post
Share on other sites

There is a lot wrong with your code, for instance it's highly recursive and it will crash quickly. Second, your pause function has no exit condition, so it pauses with no way to unpause your script.
 

this is obviously not the exact script but its dumbed down version so you dont have to read the wall of text.  thought it might do aswell since the problem is not the script code there is something wrong the adlib function stopping it from working correctly which i just pasted in.

 

This code will do what I think it is you're trying to do. I've changed the part of the code that recurses because I honestly have no idea what it is you're doing inside those functions, so I can't fix what I can't see.

HotKeySet("{F6}", "end")
HotKeySet("{F1}", "main")
HotKeySet("{F2}", "pause")
AdlibRegister("checkforerror", 1000)

Global $bPause = False
While 1
    Sleep(100)
    While $bPause
        ToolTip("Pausing")
        Sleep(100)
    WEnd
    ToolTip("")
WEnd

Func checkforerror()
    PixelSearch(936, 4, 978, 32, 0xFFD100)
    If @error Then
        $bPause = True
    EndIf
EndFunc   ;==>checkforerror


Func main()
    Send("§")
    nex()
EndFunc   ;==>main

Func nex()
    Send("§")
    tur()
EndFunc   ;==>nex
Func tur()
    Send("§")
EndFunc   ;==>tur


Func pause()
    $bPause = Not $bPause
EndFunc   ;==>pause
Func End()
    Exit
EndFunc   ;==>End

BTW, there's absolutely nothing wrong with the Adlib function, the problem was 100% your code structure and logic flow.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


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
Sign in to follow this  
Followers 0