ileandros Posted August 6, 2012 Posted August 6, 2012 Hi guys, My script is something like this: Func _Main() While 1 Call("Second") WEnd EndFunc Func Second() Call("Third") EndFunc Func Third() ;so goes on EndFunc When all the functions end then it starts over again. How can i count down everytime it starts over again? I want to add a function that is gonna run every 5 or 10 times the script runs. I tried this but didnt really worked. $run = 0 Func _Main() While 1 Call("Second") $run += 1 WEnd EndFunc I feel nothing.It feels great.
NicePerson Posted August 6, 2012 Posted August 6, 2012 Try this:$run = 0 Func _Main() While 1 < 6 Call("Second") $run += 1 WEnd EndFuncThis will Call("Second") for 5 times.
saywell Posted August 6, 2012 Posted August 6, 2012 OP doesn't want to do that, though. $run=0 While 1 call ("First") $run += 1 If $run = 5 then call ("one-in-five") $run = 0 endif wend William
ileandros Posted August 6, 2012 Author Posted August 6, 2012 saywell this is what i mean but doesnt seems to work.I already tried that but nothing. Any other ideas? I feel nothing.It feels great.
JohnQSmith Posted August 6, 2012 Posted August 6, 2012 If you are trying to get the function to run only every 5th time the script is run, you're going to have to store a counter OUTSIDE of the script. Variable values are not maintained by a script between runs. Try storing the count value in an external file, as a system variable, or in the registry. Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".
ileandros Posted August 9, 2012 Author Posted August 9, 2012 JohnQSmithIf you are trying to get the function to run only every 5th time the script is run, you're going to have to store a counter OUTSIDE of the script.Are you sure? I did found a way to do it I feel nothing.It feels great.
JohnQSmith Posted August 9, 2012 Posted August 9, 2012 Are you sure? I am 100% positive. You need to clarify what you are asking for. Do you want the function to be called every 5th time the script is run or do you want the function to be called every 5th time the script loops? I based my answer on the following statement. I want to add a function that is gonna run every 5 or 10 times the script runs. If I have a script called RunMe.au3 $run = 0 $run = $run + 1 ConsoleWrite($run) then no matter whether I "run" (execute) RunMe.au3 one time or one thousand times, the output will always be "1". If I have a script called LoopMe.au3 $loop = 0 $count = 5 While $loop < $count $loop = $loop + 1 ConsoleWrite($loop) WEnd then the output will increment. I think what you're looking for is something like this Global $loopCounter = 0 While 1 Call("_Main") If $loopCounter > 33 Then Exit WEnd Func _Main() $loopCounter += 1 ConsoleWrite("_Main function" & @CRLF) Call("Second") EndFunc Func Second() ConsoleWrite(" Second function" & @CRLF) If Mod($loopCounter, 5) = 0 Then Call("Third") EndFunc Func Third() ConsoleWrite(" Third function" & @CRLF) EndFunc Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".
ileandros Posted August 9, 2012 Author Posted August 9, 2012 I think what you're looking for is something like this Global $loopCounter = 0 While 1 Call("_Main") If $loopCounter > 33 Then Exit WEnd Func _Main() $loopCounter += 1 ConsoleWrite("_Main function" & @CRLF) Call("Second") EndFunc Func Second() ConsoleWrite(" Second function" & @CRLF) If Mod($loopCounter, 5) = 0 Then Call("Third") EndFunc Func Third() ConsoleWrite(" Third function" & @CRLF) EndFunc Yeah maybe my bad dialect. But it doesnt work this way. Actually it works but not perfectly. It gets confused because the script is very long with a lot of functions calling each other. So i used TimeInit(). I feel nothing.It feels great.
JohnQSmith Posted August 9, 2012 Posted August 9, 2012 I'm glad you found an answer. Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now