Jump to content

Function count help


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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