Jump to content

Problem with while loops and if


Recommended Posts

Hi coders, I have an issue with this code I wrote. Though the post seems massive, It's a very quick and simple question and won't take much time. Here's the code:

FirstFunc()
Otherfunc()
SecondFunc()
Func FirstFunc()
Dim $ClickCount=17;should be 0, but i put 17 to shorten and show you just 3 clicks
Dim $condition=Random(1,5,1)
MsgBox(0,"value","First condition is "&$condition)
    While 1
        If $condition>1 Then;made almost always possible by purposal
            If $ClickCount<20 Then; ITS ELSE DOESNT WORK!
                While 1
                    If $ClickCount<20 Then
                        Local $RandClick[2] = [Random(200,400,1), Random(300,500,1)]
                        MouseClick("left", $RandClick[0], $RandClick[1])
                        Sleep(500)
                        Local $condition2=Random(1,10,1);useless here, i just put it to closely report how my real code was!
                        MsgBox(0,"value","Second condition is "&$condition2)
                        If $condition2>0 Then
                            MsgBox(0,"1","1")
                            Sleep(500);(here it was the real code, i put this for this example)
                            If $condition2>0 Then
                                MsgBox(0,"1","2")
                                Sleep(500);(here it was the real code, i put this for this example)
                                If $condition>9 Then;MADE ALMOST IMPOSSIBLE BY PURPOSAL, TO make it do all the clicks
                                    MsgBox(0,"1","3")
                                    Sleep(500);(here it was the real code, i put this for this example)
                                    If $condition>9 Then;MADE ALMOST IMPOSSIBLE BY PURPOSAL, TO make it do all the clicks
                                        MsgBox(0,"1","4")
                                        ExitLoop
                                    Else
                                        ContinueLoop
                                    EndIf
                                EndIf
                            EndIf
                        EndIf
                    $ClickCount+=1
                    EndIf
                WEnd
            Else;WHY THE CODE DOWN HERE NEVER RUNS?????
                MsgBox(0,"wwww","Clicks are 20, so we go out of the func and proceed to the next one");HERE DOESNT WORK...
                ExitLoop;If clicks are more than 20, then exit from this cycle and proceed with next func
            Endif
        OtherFunc()
        EndIf
    ExitLoop
WEnd
EndFunc

Func Otherfunc()
    MsgBox(0,"Yay!","Going to the second func!")
    Sleep (1000)
EndFunc

Func SecondFunc()
    MsgBox(0,"Second","We are in the second Func")
EndFunc

Basically it states a pair of conditions to decide if make some random clicks or not.

The problem I'm having is the following:

I don't know how to make it exit from the FirstFunc() correctly to execute the following functions.

You see there 2 identical If statements

If $ClickCount<20 Then

Well, I want the function to exit from FirstFunc() when 20 random click are made so it proceeds to the others.

Here is a working solution: (About line 38-42 if you pasted full code in Scite)

EndIf
                                EndIf
                            EndIf
                        EndIf
                    $ClickCount+=1
                    Else
                        ExitLoop 2;exits from both loops
                    EndIf
                WEnd

But As you can see in the first code I posted, I want it to exit because of the main If

If $ClickCount<20 Then; ITS ELSE DOESNT WORK!

In fact, as I said, its else doesn't work

Else;WHY THE CODE DOWN HERE NEVER RUNS?????
                MsgBox(0,"wwww","Clicks are 20, so we go out of the func and proceed to the next one");HERE DOESNT WORK...
                ExitLoop;If clicks are more than 20, then exit from this cycle and proceed with next func
            Endif

Have you any clue why this? I'm almost sure it's a problem of If, else, Endif Placing, or a matter of loops, but can't figure out a solution, tried many, but none worked.

Thanks to all

Edited by niubbone
Link to comment
Share on other sites

without running the code, Im going to say your code never exits the secong while 1 loop.

Yes but why? I already knew that... I clearly stated thet If clickcount is <20 code keeps going, ELSE if clickcount is 20 or higher, it must exits while loop, and so the first while loop does....

I Don't get whats wrong. Only solution seems to put a Exitloop 2 in the second While loop, but i wanted it to do that in the 1st while...

EDIT:

Other solution seems to put second while loop like this, TOTALLY ERASING that If clickcount<20 checks:

If $condition>2 Then
                While $ClickCount<20

Seems a valid solution but still that if out there not executing..... wtf????

Edited by niubbone
Link to comment
Share on other sites

Hi,

for exiting the second while loop, $condition has to be bigger then 9.

Since $condition never changes in the 2nd while loop, it will run 4 ever: !! $condition=Random(1,5,1) !!

You missed the else for the 2nd If $clickcount < 20:

If $ClickCount<20 Then; ITS ELSE DOESNT WORK! <- can't, because you are sticking in the while loop following
                While 1
                    If $ClickCount<20 Then ; !! This else is missing with an exit loop !!
                    ; or you might change it to: If ClickCount = 20 Then ExitLoop
                    ;code as follows

;-))

Stefan

Edited by 99ojo
Link to comment
Share on other sites

Hi,

for exiting the second while loop, $condition has to be bigger then 9.

Since $condition never changes in the 2nd while loop, it will run 4 ever: !! $condition=Random(1,5,1) !!

You missed the else for the 2nd If $clickcount < 20:

If $ClickCount<20 Then; ITS ELSE DOESNT WORK! <- can't, because you are sticking in the while loop following
                While 1
                    If $ClickCount<20 Then ; !! This else is missing with an exit loop !!
                    ; or you might change it to: If ClickCount = 20 Then ExitLoop
                    ;code as follows

;-))

Stefan

Thanks, i made it another way. Still to test if fully working though.
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...