Jump to content

Running funcitons continously but each function only in desired variable.


 Share

Recommended Posts

Hello,

I still have a small issue  with Autoit. I'm testing 3 examples function : a,b,c. 

Func a()
    $i = 0 to 3 Step 1
        a()
    Next
EndFunc
Func b()
    $i = 0 to 4 Step 1
        a()
        Next
EndFunc
Func c()
    $i = 0 to 5 Step 1
        a()
        Next
EndFunc

For $i = 0 to 10 Step 1
            a()
            b()
            c()
Next

 

I want functions running a then b then c 10 times and each function stay with the variable like mentioned above. It means function a runs  1 time then jumps next function b then jumps next function c for continiously 10 times, but each function stays only in variable listed in the function mentioned.

What I recieved are function a run 3 times then function b runs 4 times and function c runs 5 times. 

I´m messing over 3 days and still cant find any solutions. Any idea how I can do it? Thanks for advanced!

Link to comment
Share on other sites

Why is Func a() calling itself?

Func a()
    $i = 0 to 3 Step 1
        a()
    Next
EndFunc

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

Hi @Lakers.

There are some problems with your current code.

Firstly, a For keyword is missing on line 2, 7, and 12.

Second, as @taurus905 points out, the a function is calling itself without a conditional, resulting in the program always crashing with recursion level exceeded error message.

Your text, describing the expected behavior of your script also seems a bit confusing to me, so I'm guessing english is not your first language?

I think you want the loop to run a then b and then c 10 times, and your code is written so that can happen.

What i don't currently understand is what the functions a, b and c are supposed to be doing?

You claim to have spend 3 days on this, but since the code is not working, I'm guessing either this is not the actual code you have been spending 3 days on, or you have spend 3 days trying to understand basic AutoIt3 syntax?

Either case, I'm interested in helping, but i would say ANYONE would need more information to go on to even be able to start helping you with anything other than the basic syntax problems, currently.

Edited by genius257
brainfart wrote array instead of loop
Link to comment
Share on other sites

I´m sorry for confusing. English is not my first language. 

I want the functions a,b,c running in a loop like mentioned in the coding., like this, a->b->c->a->b->c->a->b->c and continously.

Function A will runs only in variable 0-3, Function b will run in variable 0 to 4, and Function c will run in variable 0 to 5.  I hop its clearify now. Thanks in advanced

For $i = 0 to 10 Step 1          
   a()          
   b()          
   c() 
Next  
Link to comment
Share on other sites

6 hours ago, Andreik said:

Something like this?

For $i = 0 to 10 Step 1      
   If $i <= 3 Then a()          
   If $i <= 4 Then b()          
   If $i <= 5 Then c() 
Next

But why to loop up to 10 in this case?

You didnt understand my requirements. Lets me explain. The functions running 10 times, but the variable of function a will be only 0 to 3 and not exceeded to 4. Ssame for other functions. That mean I dont want function a to runs in 4th time with 4th variable, it will run 4th time with 0th variable. I hope its clearify now. Thanks for helping and understanding!

Link to comment
Share on other sites

Hi @Lakers.

The most helpful thing you could do is post the actual code, if it is different from the code you gave initially. This will allow us all to understand your problem better.

Your explanation and clarification of wanted functionality still seems confusing.

If you want your code to loop to run 10 times, where a is called when $i is between 0 and 3, b is called when $i is between 0 and 4, and c is called when $i is between 0 to 5, then the answer given by @Andreik is correct.

If you want a, b and c to always be called, but something in each function to do something, depending of your conditions, then try this:

Func a($i)
    If $i <= 3 Then
        ConsoleWrite("condition in a triggered. $i is "&$i&@CRLF)
    EndIf
EndFunc

Func b($i)
    If $i <= 4 Then
        ConsoleWrite("condition in b triggered. $i is "&$i&@CRLF)
    EndIf
EndFunc

Func c($i)
    If $i <= 5 Then
        ConsoleWrite("condition in c triggered. $i is "&$i&@CRLF)
    EndIf
EndFunc

For $i = 0 to 10 Step 1
   a($i)
   b($i)
   c($i)
Next

 

If neither of these is right, either post more code to help us understand the problem, or explain what it is you expect the code to do from start to end step by step.

Edited by genius257
Link to comment
Share on other sites

I think the OP may mean this:

For $i = 0 To 12
    ConsoleWrite(@CRLF & "GLOBAL counter = " & $i & @CRLF)
    a($i)
    b($i)
    c($i)
Next

Func a($iA)
    $iA = mod($iA,4)    ; cycling 0-3 inclusive
    ConsoleWrite("Func A counter = " & $iA & @CRLF)
EndFunc

Func b($iB)
    $iB = mod($iB,5)    ; cycling 0-4 inclusive
    ConsoleWrite("Func B counter = " & $iB & @CRLF)
EndFunc

Func c($iC)
    $iC = mod($iC,6)    ; cycling 0-5 inclusive
    ConsoleWrite("Func C counter = " & $iC & @CRLF)
EndFunc

 

Link to comment
Share on other sites

Func a($sta,$ena)

For $i = $sta to $ena Step 1
    function coding
 NExt
 
 Func b($stb,$enb)

For $i = $stb to $ebn Step 1
    function coding
 NExt
 
 Func c($stc,$enc)

For $i = $stc to $enc Step 1
    function coding
 NExt
 
 For $i = 0 to 10 Step 1
        a(0,3)
        b(0,4)
        c(0,5)
  Next

Is it the right directions? 
Thanks in advanced and happy holidays.

Link to comment
Share on other sites

On 10/6/2023 at 12:37 PM, Andreik said:

Are you asking us if it's right? Don't you know what do you want to achieve? :lol:

I already told what I want to achieve with the script. Its basically 3 functions running in loop and each function runs in desired $i I choosen. I hope its clear enough to understand now. Thanks for your reading and understanding

Link to comment
Share on other sites

On 10/6/2023 at 11:16 AM, RTFC said:

I think the OP may mean this:

For $i = 0 To 12
    ConsoleWrite(@CRLF & "GLOBAL counter = " & $i & @CRLF)
    a($i)
    b($i)
    c($i)
Next

Func a($iA)
    $iA = mod($iA,4)    ; cycling 0-3 inclusive
    ConsoleWrite("Func A counter = " & $iA & @CRLF)
EndFunc

Func b($iB)
    $iB = mod($iB,5)    ; cycling 0-4 inclusive
    ConsoleWrite("Func B counter = " & $iB & @CRLF)
EndFunc

Func c($iC)
    $iC = mod($iC,6)    ; cycling 0-5 inclusive
    ConsoleWrite("Func C counter = " & $iC & @CRLF)
EndFunc

 

Can you do it in msgbox for me better understanding? Thanks for your advice helping.

Link to comment
Share on other sites

On 10/6/2023 at 3:16 AM, RTFC said:

I think the OP may mean this:

For $i = 0 To 12
    ConsoleWrite(@CRLF & "GLOBAL counter = " & $i & @CRLF)
    a($i)
    b($i)
    c($i)
Next

Func a($iA)
    $iA = mod($iA,4)    ; cycling 0-3 inclusive
    ConsoleWrite("Func A counter = " & $iA & @CRLF)
EndFunc

Func b($iB)
    $iB = mod($iB,5)    ; cycling 0-4 inclusive
    ConsoleWrite("Func B counter = " & $iB & @CRLF)
EndFunc

Func c($iC)
    $iC = mod($iC,6)    ; cycling 0-5 inclusive
    ConsoleWrite("Func C counter = " & $iC & @CRLF)
EndFunc

 

@Lakers If you use the script provided by @RTFC, you can run it using "Tools" and "Go" or by pressing "F5" on your keyboard.

This will give you all the outputs on one screen for you to determine if this is what you want or expect.

taurus905

Running funcitons continously.png

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

@Lakers Please post at least code that compiles or write an example in a different language, even you could try to write your question also in your native language.

I think you are saying (and at the bottom of the post example code):
Loop 0-3 call a b c just having $i to be equal to $i, Loop 4 call a b c but then a produces 0, Loop 5 call a b c but then a produces 1 and b produces 0 and c produces 5

so then output would be

a 0 b 0 c 0
a 1 b 1 c 1
a 2 b 2 c 2
a 3 b 3  c 3
a 0 b 4 c 4
a 1 b 0 c 5
a 2 b 1 c 0 
......... 

and then your answer is potentially in: https://www.autoitscript.com/autoit3/docs/keywords/Static.htm but it really depends on your requirements to be clear 

write down what you expect $i to be in output

0 1 2 3        or       0 1 2 3 0 1 2 3 0 1

0 1 2 3 4    or        0 1 2 3 4 0 1 2 3 4

0 1 2 3 4 5   or     0 1 2 3 4 5 0 1 2 3

Below my try to understand

  • I have to guess like the others: 
    "That mean I dont want function a to runs in 4th time with 4th variable, it will run 4th time with 0th variable."
  • Impossible. your original coding example calls all functions 11 times
    "What I recieved are function a run 3 times then function b runs 4 times and function c runs 5 times." 

     

Running 10 times is either 0-9 or 1-10 and I like the answers suddenly having 0-12😉 

So coding that would be

For $i = 1 to 10 Step 1
    consolewrite($i & @CRLF)
Next

So then getting the first post up and running by 

  • fixing for loops
  • replacing recursive loop by calling a new function coding with parameter $i
  • and have fun if you prefer the msgbox just uncomment the line 😉
#include <MsgBoxConstants.au3>

Func a()
    for $i = 0 to 3 Step 1
        coding($i)
    Next
EndFunc
Func b()
    for $i = 0 to 4 Step 1
        coding($i)
    Next
EndFunc
Func c()
    for $i = 0 to 5 Step 1
        coding($i)
    Next
EndFunc
func coding($i)
;~  MsgBox($MB_SYSTEMMODAL, "Title", $i & @CRLF & "This message box will timeout after 1 seconds or select the OK button.", 1)
    consolewrite($i & @tab)
EndFunc
For $i = 1 to 10 Step 1
    consolewrite($i & @CRLF)
    a()
    b()
    c()
Next

assuming you give us the right direction with start and endvalue I would come to this

#include <MsgBoxConstants.au3>

Func a()
    static $i=-1
    $i= (( $i=3 ) ? (0) : ($i+1))
    coding($i)
EndFunc

Func b()
    static $i=-1
    $i= (( $i=4 ) ? (0) : ($i+1))
    coding($i)
EndFunc

Func c()
    static $i=-1
    $i= (( $i=5 ) ? (0) : ($i+1))
    coding($i)
EndFunc
func coding($i)
;~  MsgBox($MB_SYSTEMMODAL, "Title", $i & @CRLF & "This message box will timeout after 1 seconds or select the OK button.", 1)
    consolewrite($i & @tab)
EndFunc
For $i = 0 to 9 Step 1
    consolewrite("Loop " & $i & ": ")
    a()
    b()
    c()
    consolewrite(@crlf)
Next

and the output

Loop 0: 0   0   0   
Loop 1: 1   1   1   
Loop 2: 2   2   2   
Loop 3: 3   3   3   
Loop 4: 0   4   4   
Loop 5: 1   0   5   
Loop 6: 2   1   0   
Loop 7: 3   2   1   
Loop 8: 0   3   2   
Loop 9: 1   4   3

 

Edited by junkew
edit: using ternary operator instead of if..then
Link to comment
Share on other sites

Hello,

Thanks for the sharing information. I´ve tried to run the coding in Scite but cant get it running or compele. Here are the screenshot of my Scite. Any idea how to fix this? I´m using a laptop Windows 11 Pro x64.
Thanks in advance

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