Sign in to follow this  
Followers 0
cheeseandcereal

How to stop a running function?

7 posts in this topic

#1 ·  Posted (edited)

So I'm writing a code with some functions and I want my function to stop running if the no button is pressed in the msgbox. here is the code:

Func Button8()
$confirm4 = MsgBox ( 4+64, "Confirmation", "Are you sure you would like to restore your minecraft jar files? This will restore all of your minecraft jar files from the last time that you backed them up. This means that if you are currently having problems with the gametype changer function or you have destroyed a minecraft jar with mods, this should fix it. Use this function before the Old Restore function. *Note* The restore function only restores the jar files that the game changer uses, it will not restore the jar files for minecraft itself. To do that, you have to use the restore function THEN change the gametype afterwards. Continue?" )
If $confirm4 = 6 Then
DirRemove ( "C:GametypeSwitcherMinecraftVersions1.8.1", 1 )
DirRemove ( "C:GametypeSwitcherMinecraftVersions1.0.0", 1 )
DirRemove ( "C:GametypeSwitcherMinecraftVersions1.1.0", 1 )
$check21 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.0.0", "C:GametypeSwitcherMinecraftVersions", 1 )
$check23 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.1.0", "C:GametypeSwitcherMinecraftVersions", 1 )
$check24 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.8.1", "C:GametypeSwitcherMinecraftVersions", 1 )
EndIf
IF $check21 = 1 And $check23 = 1 And $check24 = 1 Then
MsgBox ( 0, "Success", "The restoration of the backup for working minecraft jar files was succesful. If gametype changing was messed up or mods destroyed a minecraft jar, it should now be restored and working. If these functions still do not work, try using the old restore function." )
Else
$fail8 = MsgBox ( 4+16, "Failure", "The restoration was a failure. This means that your gametype changer functions may not work properly and it is recommended that you try again. Would you like to try again?" )
EndIf
If $fail8 = 6 Then Button8()
EndFunc

So when I initially start this function a message box will pop up with either yes or no and if you click no, the operation will not happen, but I will get the failed msgbox because of the else function. I'm wondering if there is a command that will stop the function so if I press the no button on the first msgbox, nothing else will pop up. any help would be greatly appreciated

Edited by cheeseandcereal

Share this post


Link to post
Share on other sites



Look in this wiki post http://www.autoitscript.com/wiki/Interrupting_a_running_function


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

#3 ·  Posted (edited)

those examples are about interrupting functions in a GUI script. Here are other ways:

to interrupt a script and then resume, set a hot key such as the break key. When hit, this will call TogglePause(), which will keep running and cause your script to only do that, till you hit break again.

Dim $Paused = False
HotKeySet("{PAUSE}", "TogglePause")
Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

To exit a function, set up a hot key (here, again, the break key). Make it call a simple function to set a boolean to true, $bDone. In the function you want to exit, you can check for that value, and when true, exit:

Dim $bDone = False
HotKeySet("{PAUSE}", "quitscript")
while not $bDone
   sleep(500)
wend
Func quitscript()
   $bDone = true
EndFunc

You can use that hot key to bring up a msgbox where you can decide if you want to quit or not.

Edited by rodent1

Share this post


Link to post
Share on other sites

Func Button8()
$confirm4 = MsgBox ( 4+64, "Confirmation", "Are you sure you would like to restore your minecraft jar files? This will restore all of your minecraft jar files from the last time that you backed them up. This means that if you are currently having problems with the gametype changer function or you have destroyed a minecraft jar with mods, this should fix it. Use this function before the Old Restore function. *Note* The restore function only restores the jar files that the game changer uses, it will not restore the jar files for minecraft itself. To do that, you have to use the restore function THEN change the gametype afterwards. Continue?" )
If $confirm4 = 6 Then
    DirRemove ( "C:GametypeSwitcherMinecraftVersions1.8.1", 1 )
    DirRemove ( "C:GametypeSwitcherMinecraftVersions1.0.0", 1 )
    DirRemove ( "C:GametypeSwitcherMinecraftVersions1.1.0", 1 )
    $check21 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.0.0", "C:GametypeSwitcherMinecraftVersions", 1 )
    $check23 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.1.0", "C:GametypeSwitcherMinecraftVersions", 1 )
    $check24 = DirCopy ( "C:GametypeSwitcherMinecraftVersionsBackupNewBackup1.8.1", "C:GametypeSwitcherMinecraftVersions", 1 )

    IF $check21 = 1 And $check23 = 1 And $check24 = 1 Then
        MsgBox ( 0, "Success", "The restoration of the backup for working minecraft jar files was succesful. If gametype changing was messed up or mods destroyed a minecraft jar, it should now be restored and working. If these functions still do not work, try using the old restore function." )
        Else
        $fail8 = MsgBox ( 4+16, "Failure", "The restoration was a failure. This means that your gametype changer functions may not work properly and it is recommended that you try again. Would you like to try again?" )
    EndIf
    If $fail8 = 6 Then Button8()
Else
    MsgBox(0, "Stop", "Stop was pressed.")
EndIf
EndFunc

u can replace the msgbox with a sleep(0)

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