Sign in to follow this  
Followers 0
Chobyhy

Reloading Script

12 posts in this topic

First question. If i use a script where it will keep adding +1 to variable will the variable reset when the script restarts?

Second Question: How do you make it so the script restarts?

Share this post


Link to post
Share on other sites



First question. If i use a script where it will keep adding +1 to variable will the variable reset when the script restarts?

Second Question: How do you make it so the script restarts?

Question 1 = Yes, I had the problem so I had the variable but in an ini file (I'm by restart you mean you close the script and re open it)

Question 2 = Well obviously you could exit it and then open it again manually... or you could and a function in there somewhere and if done right it would restart after your done...

Piano_Man


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

put in a loop

edit: forgot the add part :P

Edit again my bad + before =

$i = 1
while 1
msgbox(0,"your loop is","Your loop number is " & $i)
$i+=1
Sleep(1000)
wend
Edited by thatsgreat2345

Share this post


Link to post
Share on other sites

that doesnt explain how to reload my script

Share this post


Link to post
Share on other sites

$i = 1
Start()
func Start()
msgbox(0,"your loop is","Your loop number is " & $i)
$i+=1
Sleep(1000)
Start()
EndFunc

Share this post


Link to post
Share on other sites

$i = 1
Start()
func Start()
msgbox(0,"your loop is","Your loop number is " & $i)
$i+=1
Sleep(1000)
Start()
EndFunc
Quickest way to get a recursion error. Bad logic calling a function within itself.

@Chobyhy

Where is your script so advice can be given to allow it to restart as there is no magic goto start of script keywork in AutoIt.

Share this post


Link to post
Share on other sites

Quickest way to get a recursion error. Bad logic calling a function within itself.

@Chobyhy

Where is your script so advice can be given to allow it to restart as there is no magic goto start of script keywork in AutoIt.

Yes i know about recursion limit :P just giving simple examples cuz im at loss to as what he wants :nuke:

Share this post


Link to post
Share on other sites

well im not making it the "go to" script or other wise i would use the $var = 0 command instead of restarting. actually wtf was i thinking i can just use $var = 0 command

Share this post


Link to post
Share on other sites

Ok, let me continue this topic, since no answer has been given on how to restart the script withing the script.

In my case I want make the script restart itself as soon as it has been modified, so I can see the result without need in close current script and start it again, as soon as I hit save button in my editor.

In AHK there is a built-in feature "Reload" which restarts the script. In AI3 I don't see such feature, so I guess the only way is to run new instance of the script and then exit the "old" script?

Share this post


Link to post
Share on other sites

Unfortunately with the method I've described I see no "easy" way trace errors (if script failed to start, then don't exit the "old" instance) without going nuts codding too complicated for what it worth...

P.S. we can't edit our posts? :)

Share this post


Link to post
Share on other sites

I'm not sure if this is what you mean but this is how you could make a script that restarts itself and sends some information to the new instance of the script.

$MyVariable = 0;This is the variable we are going to pass data too initialize it for the first time of running must be before the commandline check

If $CMDLine[0] > 0 then;check the commandline to see if any variable data was passed
    For $i = 1 to $CMDLine[0]
        If StringLeft($CMDLine[$i],4) = "/var" then $MyVariable = StringTrimLeft($CMDLine[$i],5)
    Next
EndIf
    
    
    
    
;start the script   
Msgbox(0,"","Start of script $MyVariable = " & $MyVariable)


For $i = $MyVariable to $MyVariable +10
    Msgbox(0,"","For loop " & $i,1)
    $MyVariable = $i
Next

If $MyVariable = 30 then Exit
_restartScript($MyVariable);restart the script and send the data from $MyVariable



Func _restartScript($Var=0)
    If @compiled then 
        Run('"' & @ScriptFullPath & '"' &  " /var:" & $var, @ScriptDir)
    Else
        Run (@AutoItExe & " /AutoIt3ExecuteScript " &  FileGetShortName(@ScriptFullPath) & " /var:" & $Var, @ScriptDir)
    EndIf
    Exit
EndFunc

Share this post


Link to post
Share on other sites

Thanks for the response.

Doesn't look to complicated, however, this doesn't check if the script has been successfully restarted...what if the script has been modified and has syntax error?

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