Jump to content

Reloading Script


Chobyhy
 Share

Recommended Posts

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]
Link to comment
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:

Link to comment
Share on other sites

  • 1 year later...

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?

Link to comment
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? :)

Link to comment
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
Link to comment
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?

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