Sign in to follow this  
Followers 0
Nico401

loop's problem

8 posts in this topic

Hello,

I am French so I will tray to have a good English

I have a problem with loops :

while 1=1
    While $combat = 'BEB998'
        Call ("Fauchage")
        ExitLoop
    WEnd
    
    
    While $combat = '312737' 
        Call ("Combat")
        ExitLoop
    WEnd
    
        
    While $defi = 'FFFFFF'
        Call ("Defi")
                                ExitLoop
    WEnd
        

    While $niveau = 'FF6100'
        Call ("Niveau")
        ExitLoop
    WEnd
        
Wend

Now If an expression is true the code always execute the same and he don't test others and I want it always test all conditions.

I don't understand definitely loop's system.

Share this post


Link to post
Share on other sites



I think you want If/Then statements vice While/WEnd:

while 1
    If $combat = 'BEB998' Then Fauchage()
    
    If $combat = '312737'  Then Combat()
        
    If $defi = 'FFFFFF' Then Defi()

    If $niveau = 'FF6100' Then Niveau()
Wend

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Arrgh! PsaltyDS beat me to the post, however its not completely what the OP was looking for. After their functions are called they want to exit the loop. I tried a few thing including Return 0 and Return -1 to emulate ExitLoop, but couldn't figure it out. So instead I did it this way. Anyone know what the correct Return value is for ExitLoop?

@Nico401 - you'll need to remove the ";~" and the 3 lines beginning with $combat = Inputbox(...). I left it in for you to get an idea of what's going on.

$loop = True
while $loop == True
    $combat = InputBox("Test","enter valaue")
    If $combat == '1' Then Fauchage()
    If $combat == '2' Then Combat()
;~  If $combat == 'BEB998' Then Call ("Fauchage")
;~  If $combat = '312737' Then Call ("Combat")
;~  If $defi == 'FFFFFF' Then Call ("Defi")
;~  If $niveau == 'FF6100' Then Call ("Niveau")
;~  Sleep(100)
WEnd
MsgBox(0,"", "Exit Loop successfully")
Exit

Func Fauchage()
    ;; some code
    MsgBox(0,"","Inside Function 1")
    Global $loop = False  ;; <-- same as ExitLoop
EndFunc
Func Combat()
    ;; some code
    MsgBox(0,"","Inside Function 2")
    Global $loop = False  ;; <-- same as ExitLoop
EndFunc
Edited by ssubirias3

Share this post


Link to post
Share on other sites

I tested your codes but if one of these conditions is true , it always goes on to execute it .

If you want the entirely code :

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.4.9
 Author: Lassaux Nicolas

 Script Function:
    
#ce ----------------------------------------------------------------------------

AutoItSetOption("RunErrorsFatal", 0)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)

; ------------------------------------------------------------------------------
;                               Ouvre Dofus
;-------------------------------------------------------------------------------

WinActivate("Dofus"); ouvre dofus.
;Sleep (2000);attend 2 sec.

;-------------------------------------------------------------------------------
;                                Détéction
;-------------------------------------------------------------------------------

$combat = PixelGetColor( 1200, 943 ); detection du conteur.
$combat = Hex($combat, 6)   

$niveau = PixelGetColor( 635,458 ); detection du bouton passer.
$niveau = Hex($niveau, 6);passage en hexa

$defi = PixelGetColor( 927, 324 ); detection du bouton defi.
$defi = Hex($defi, 6);passage en hexa

;-------------------------------------------------------------------------------
;                            S'occupe de faucher
;-------------------------------------------------------------------------------

Func Fauchage()
    $ble = PixelSearch ( 0,0,1279,1023, 0xE7C72C, 4 );cherche couleur du blé.
    MouseClick( "", $ble[0], $ble[1], 1, 0 );clique sur la couleur du blé.
    Sleep (500)
    MouseClick( "left", $ble[0]+44, $ble[1]+50, 1, 0);clique sur faucher.
    Sleep (14000)
    Global $loop = False ;; <-- same as ExitLoop
EndFunc
;-------------------------------------------------------------------------------
;                    S'occupe de refuser un défi/échange
;-------------------------------------------------------------------------------

Func Defi()                 
    MouseClick("", 803, 471, 1, 0);si il y a un defi ,le refuser.
    Sleep (2000);a enlever
EndFunc

;-------------------------------------------------------------------------------
;                     S'occupe du passage au niveau sup.
;-------------------------------------------------------------------------------

Func Niveau()
    MouseClick("", 675, 456, 1, 0); si il y a le passage a niveau cliquer dessus.
    Sleep (2000);a enlever
EndFunc

;-------------------------------------------------------------------------------
;                              S'occupe du BIP
;-------------------------------------------------------------------------------

func Bip()
    SoundPlay("blip.wav")
endfunc

;-------------------------------------------------------------------------------
;                              S'occupe du combat
;-------------------------------------------------------------------------------


Func Combat()
    MouseClick("", 1179, 732, 1, 0);clique sur passer.
    Sleep (1000);a enlever
    Global $loop = False ;; <-- same as ExitLoop
EndFunc
;-------------------------------------------------------------------------------

$loop = True
while $loop == True
    If $combat == 'BEB998' Then  Call ("Fauchage")
    If $combat == '312737' Then Call ("Combat")
    If $defi == 'FFFFFF' Then Call ("Defi")
    If $niveau == 'FF6100' Then Call ("Niveau")
    Sleep(100)
WEnd
MsgBox(0,"", "Exit Loop successfully")
Exit

Share this post


Link to post
Share on other sites

I tested your codes but if one of these conditions is true , it always goes on to execute it .

Isn't that what you want? If $combat == (is equal to) 'BEB998' Then Call ("Fauchage")... I thought that's what you wanted to happen? If it isn't what you want to happen, please explain what should happen when $combat == "BEB998".

The other thing I noticed is that you didn't apply the necessary changes to your other functions. Your script is dealing with 4 conditions that result in 4 different function calls. If you want the loop to Exit after any of the 4 functions have been performed then you need all 4 functions to

Global $loop = False ;; <-- same as ExitLoop

You have that correctly in Fauchage() and Combat(), but not in Defi() or Niveau(). Hopefully this clears up the confusion.

Share this post


Link to post
Share on other sites

I'm not sure when you want to exit the loop. Is it after at least one of the conditions is true and all four have been tested?

If so, something like:

$loop = True
while $loop == True
    If $combat == 'BEB998' Then  
        Call ("Fauchage")
        $loop=False
        EndIf
    If $combat == '312737' Then 
        Call ("Combat")
        $loop = False
        EndIf
    If $defi == 'FFFFFF' Then 
        Call ("Defi")
        $loop = False
        EndIf
    If $niveau == 'FF6100' Then 
        Call ("Niveau")
        $loop = False
        EndIf
    Sleep(100)
WEnd

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Perhaps you mean to only have one of these options execute per loop? Then it would be:

$loop = True
while $loop == True
    Select
        Case $combat == 'BEB998'
            Fauchage()
        Case $combat == '312737'
            Combat()
        Case $defi == 'FFFFFF'
            Defi()
        Case $niveau == 'FF6100'
            Niveau()
    EndSelect
    Sleep(100)
WEnd

:)

P.S. I don't get your use of Call(). While technically usable, it's an ugly holdover from AutoIt v2, and not required anymore. You can call functions in AutoIt v3 without Cal().

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Ok thank you I have find the solution :

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.4.9
 Author: Lassaux Nicolas

 Script Function:
    
#ce ----------------------------------------------------------------------------

AutoItSetOption("RunErrorsFatal", 0)
AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 0)

; ------------------------------------------------------------------------------
;                               Ouvre Dofus
;-------------------------------------------------------------------------------

WinActivate("Dofus"); ouvre dofus.

;-------------------------------------------------------------------------------
;                            S'occupe de faucher
;-------------------------------------------------------------------------------

Func Fauchage()
    $ble = PixelSearch ( 0,0,1279,1023, 0xE7C72C, 4 );cherche couleur du blé.
    MouseClick( "", $ble[0], $ble[1], 1, 0 );clique sur la couleur du blé.
    Sleep (500)
    MouseClick( "left", $ble[0]+44, $ble[1]+50, 1, 0);clique sur faucher.
    Sleep (14000)
EndFunc
;-------------------------------------------------------------------------------
;                    S'occupe de refuser un défi/échange
;-------------------------------------------------------------------------------

Func Defi()                 
    MouseClick("", 803, 471, 1, 0);si il y a un defi ,le refuser.
EndFunc

;-------------------------------------------------------------------------------
;                     S'occupe du passage au niveau sup.
;-------------------------------------------------------------------------------

Func Niveau()
    MouseClick("", 675, 456, 1, 0); si il y a le passage a niveau cliquer dessus.
EndFunc

;-------------------------------------------------------------------------------
;                              S'occupe du BIP
;-------------------------------------------------------------------------------

func Bip()
    SoundPlay("blip.wav")
endfunc

;-------------------------------------------------------------------------------
;                              S'occupe du combat
;-------------------------------------------------------------------------------


Func Combat()
    MouseClick("", 1179, 732, 1, 0);clique sur passer.
    Sleep (1000);a enlever
EndFunc

;-------------------------------------------------------------------------------

$loop = True
while $loop == True
    
[b][u]$combat = PixelGetColor( 1200, 943 ); detection du conteur.
$combat = Hex($combat, 6)   

$niveau = PixelGetColor( 635,458 ); detection du bouton passer.
$niveau = Hex($niveau, 6);passage en hexa

$defi = PixelGetColor( 927, 324 ); detection du bouton defi.
$defi = Hex($defi, 6);passage en hexa[/u][/b]
    
    If $combat = 'BEB998' Then  Call ("Fauchage")
    If $combat = '312737' Then Call ("Bip")
    If $defi = 'FFFFFF' Then Call ("Defi")
    If $niveau = 'FF6100' Then Call ("Niveau")
    Sleep(100)
WEnd

Share this post


Link to post
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
Sign in to follow this  
Followers 0