Jump to content

Recommended Posts

Posted (edited)

Ex.

Global $test=1

settest()

func settest()

$test+=1

endfunc

func gettest()

return $test

endfunc

When this script end I want restart script.

How to restart script ?

ps.Don't use loop

thank u

Edited by ocensound
Posted (edited)

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
Posted

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.

  • Developers
Posted

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

Posted (edited)

Yeah, Thank you looklike easy >,<

but after restart

HotKeySet("{PAUSE}", "dopause")

HotKeySet("{END}", "doexit")

This key doesn't work ;(

Edited by ocensound

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