Sign in to follow this  
Followers 0
phuzE koj

End all Funcs

7 posts in this topic

This is a dummy code that I created...Now there are currently several flaws in this which I am aware of. The main goal of this is for onstop() to end all Functions(or just OnAfk()). Of course what I have here kind of does this...however it is extremely inefficient what with the infinite loop and the restarting of the program and all. :lmao:

Anyways, I'm sure there is a MUCH better way to do this. Could anyone help me out here?

$count = 1
Func OnAfk()
Do
    WinActivate("Untitled - Notepad")
    WinWaitActive("Untitled - Notepad")
    Send("{w Down}")
    Sleep(200)
    Send("{w Up}")
    Send("{F5}")
    Send("{F6}")
    Send("{F7}")
    Sleep(50000)

    $count = $count + 1
Until $count < 0
EndFunc
    
Func onstop()
    Send("#r")
    WinActivate("Run")
    WinWaitActive("Run")
    Send("C:\Documents and Settings\phuze\Desktop\WoWlauncher.au3")
    Send("{ENTER}")
    Exit
EndFunc

Share this post


Link to post
Share on other sites



Soooo... what triggers these functions? :lmao: Declaring a function does not execute it. What triggers OnAfk(), and then what calls onstop()?


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Do you think you could explain what exactly you are trying to do? Reading your "dummy code" does not tell me anything. First of all, neither of your functions are called, so ending them would be no problem at all since they are never started. OnAfk() never calls onstop() so there is no way onstop() could do anything to affect OnAfk(). And if you want to end a function, a short and sweet "Exit" tends to do the trick quite nicely.

Edit: I was beat to it. :lmao:

Edited by SerialKiller

Share this post


Link to post
Share on other sites

Well that's not the whole code, just a segment. So I guess what I should have said was that each function belongs to it's own button; ie:onstop() is triggered by a button and OnAFK() is triggered by another. And I want the Stop button to -cut- the actions of the AFK button. About the 'exit' command, I don't want to do that because I only want the function to end - not the program.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

You mean something like this?

$count = 1
Global $cancel
Func OnAfk()
$cancel = "False"
$begin = TimerInit()
Do
    If Timerdiff($begin)/1000 > 50 Then
        WinActivate("Untitled - Notepad")
        WinWaitActive("Untitled - Notepad")
        Send("{w Down}")
        Sleep(200)
        Send("{w Up}")
        Send("{F5}")
        Send("{F6}")
        Send("{F7}")
        $count = $count + 1
        $begin = TimerInit()
    Endif
    If $cancel = "True" Then Return 0
    sleep(50)
Until $count < 0
EndFunc
    
Func onstop()
    Send("#r")
    WinActivate("Run")
    WinWaitActive("Run")
    Send("C:\Documents and Settings\phuze\Desktop\WoWlauncher.au3")
    Send("{ENTER}")
    $cancel = "True"
EndFunc
Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

Share this post


Link to post
Share on other sites

Yes that is what I'm looking for, however for some reason, when I press the Stop Button, the 'do' loop continues to act, and 'w' continues to be pressed.

this is the code im using now.

$count = 1
Global $cancel
Func OnAfk()
$cancel = "False"
Do
    WinActivate("Untitled - Notepad")
    WinWaitActive("Untitled - Notepad")
    Send("{w Down}")
    Sleep(200)
    Send("{w Up}")
    Send("{F5}")
      Send("{F6}")
    Send("{F7}")
    Sleep(50000)
        $count = $count + 1
    Endif
    If $cancel = "True" Then Return 0
    sleep(50)
Until $cancel = "True"
EndFunc
    
Func onstop()
    $cancel = "True"
EndFunc

yes that is what im looking for, however for some reason

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I know what the problem is. First, here is the code you gave. It had an error in it. An Endif without an if statement. Also, i notice you took out the timerinit functions i placed in the code and replaced it back with the sleep function. The sleep function is very primative as far as functions go. The timerinit allows the code to only run at certain delays but allows your script to respond to changes during the delay period. For example, if someone presses cancel the script could be processing the first second of the 50 second delay. It would then not even get the message to cancel for another 49 seconds. Meanwhile the user is frustrated because the script isn't responding.

Func OnAfk()
$cancel = "False"
Do
    WinActivate("Untitled - Notepad")
    WinWaitActive("Untitled - Notepad")
    Send("{w Down}")
    Sleep(200)
    Send("{w Up}")
    Send("{F5}")
      Send("{F6}")
    Send("{F7}")
    Sleep(50000)
        $count = $count + 1
    If $cancel = "True" Then Return 0
    sleep(50)
Until $cancel = "True"
EndFunc
    
Func onstop()
    $cancel = "True"
EndFunc

Now for your problem with the Do until loop. The problem is that you are probably not declaring the global variable at the beginning of the script. To fix this place:

Global $cancel

at the very top of the script so that it is one of the very first things done when the script loads. If you don't do that then the script won't declare $cancel as a global variable and therefore the second function will not change the value of the $cancel variable.

Edited by The Kandie Man

"So man has sown the wind and reaped the world. Perhaps in the next few hours there will no remembrance of the past and no hope for the future that might have been." & _"All the works of man will be consumed in the great fire after which he was created." & _"And if there is a future for man, insensitive as he is, proud and defiant in his pursuit of power, let him resolve to live it lovingly, for he knows well how to do so." & _"Then he may say once more, 'Truly the light is sweet, and what a pleasant thing it is for the eyes to see the sun.'" - The Day the Earth Caught Fire

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