Jump to content

How to restart script by automaticly?


 Share

Recommended Posts

OhOhOh ,I got a problem T^T see this.

Opt("OnExitFunc","dorestart")
AutoItSetOption ("SendKeyDelay",100)
AutoItSetOption ("SendKeyDownDelay",100)
HotKeySet("{PAUSE}","dopause")
HotKeySet("{END}","doexit") 

Func dorestart()
    ConsoleWrite("RESTART"&@CRLF)
    If @Compiled Then
        Run(FileGetShortName(@ScriptFullPath))
    Else
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc

Func dopause()
    $paused=Not $paused
    If $paused=True Then
        ConsoleWrite("PAUSED"&@CRLF)
    ElseIf $paused=False Then
        ConsoleWrite("RESUME"&@CRLF)
    Else
    EndIf
    While $paused
        Sleep(1000)
    WEnd
EndFunc

Func doexit()
    ConsoleWrite("EXIT"&@CRLF)
    Exit
EndFunc

I cann't stop this when I press END clz It away restart -..-

Edited by ocensound
Link to comment
Share on other sites

Hey,

That is because you set OnExitFunc to the restart function

Opt("OnExitFunc","dorestart")

Th OnExitFunc function will be called before the script exits, this means in your case that evertime you try to exit the program the restart function gets called.

Link to comment
Share on other sites

  • Developers

Something like this?

Global $cancel=0
Opt("OnExitFunc", "dorestart")
AutoItSetOption("SendKeyDelay", 100)
AutoItSetOption("SendKeyDownDelay", 100)
HotKeySet("{PAUSE}", "dopause")
HotKeySet("{END}", "doexit")
MsgBox(1,"test","restarting in 2 seconds",2)

Func dorestart()
    if $cancel then Exit
    ConsoleWrite("RESTART" & @CRLF)
    If @Compiled Then
        Run(FileGetShortName(@ScriptFullPath))
    Else
        Run(FileGetShortName(@AutoItExe) & " " & FileGetShortName(@ScriptFullPath))
    EndIf
    Exit
EndFunc  ;==>dorestart
Func dopause()
    $paused = Not $paused
    If $paused = True Then
        ConsoleWrite("PAUSED" & @CRLF)
    ElseIf $paused = False Then
        ConsoleWrite("RESUME" & @CRLF)
    Else
    EndIf
    While $paused
        Sleep(1000)
    WEnd
EndFunc  ;==>dopause
Func doexit()
    MsgBox(0,"Cancelled","Cancelled")
    $cancel=1
    Exit
EndFunc  ;==>doexit

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 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...