Sign in to follow this  
Followers 0
ocensound

How to restart script by automaticly?

9 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



Lookup OnAutoItExit opt and the Run() function in the help file.

I like shellexecute more


[u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]

Share this post


Link to post
Share on other sites

Oh thank you so much

Share this post


Link to post
Share on other sites

#6 ·  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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Yeah, Thank you looklike easy >,<

but after restart

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

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

This key doesn't work ;(

Edited by ocensound

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