Vexhero

Why isnt my function looping? [SIMPLE]

5 posts in this topic

Hello! So I am new to Autoit but I understand the syntax a bit (Coming from C#)

 

And I created this function but for some reason it only clicks once (does the function one time)

then it stops, why is that?

HotKeySet("{ESC}", "myExit")



Global $needrest = False;

While 1
checkHealth()
WEnd



Func LC($x, $y)

MouseClick("left", $x, $y, 1, 1)

EndFunc




Func ViewReset()
   MouseClick("left",551, 55,1,1)
   Send("{UP down}")
EndFunc




Func checkHealth()

$needrest = True
$hpBar = PixelSearch(724, 58, 726, 61, 0x8A0502, 1)
;MsgBox(0,"test", "Your health is full")
if @error Then

   $findFood = PixelSearch(556, 240, 738, 493,0xE44C1B,5) 


   If NOT(@error) Then
      LC($findFood[0],$findFood[1]) ;this is the thing it only does once I want the checkHealth() function to loop
      EndIf


While($needrest)

WEnd


EndIf

EndFunc




Func myExit()
   MsgBox(0, "Exiting", "The Bot Has Quit")
   Exit
EndFunc

 

Share this post


Link to post
Share on other sites



HotKeySet("{ESC}", "myExit")
Global $needrest = False;

While 1
    checkHealth()
WEnd

Func LC($x, $y)
    MouseClick("left", $x, $y, 1, 1)
EndFunc   ;==>LC

Func ViewReset()
    MouseClick("left", 551, 55, 1, 1)
    Send("{UP down}")
EndFunc   ;==>ViewReset

Func checkHealth()
    $needrest = True
    Local $hpBar = PixelSearch(724, 58, 726, 61, 0x8A0502, 1)
    ;MsgBox(0,"test", "Your health is full")
    If @error Then
        Local $findFood = PixelSearch(556, 240, 738, 493, 0xE44C1B, 5)
        If Not (@error) Then
            LC($findFood[0], $findFood[1]) ;this is the thing it only does once I want the checkHealth() function to loop
        EndIf
;~      While ($needrest)
;~      WEnd
    EndIf
EndFunc   ;==>checkHealth

Func myExit()
    MsgBox(0, "Exiting", "The Bot Has Quit")
    Exit
EndFunc   ;==>myExit

Maybe here:
 

While ($needrest)
        WEnd

 


Regards,
 

Share this post


Link to post
Share on other sites
5 minutes ago, VIP said:
HotKeySet("{ESC}", "myExit")
Global $needrest = False;

While 1
    checkHealth()
WEnd

Func LC($x, $y)
    MouseClick("left", $x, $y, 1, 1)
EndFunc   ;==>LC

Func ViewReset()
    MouseClick("left", 551, 55, 1, 1)
    Send("{UP down}")
EndFunc   ;==>ViewReset

Func checkHealth()
    $needrest = True
    Local $hpBar = PixelSearch(724, 58, 726, 61, 0x8A0502, 1)
    ;MsgBox(0,"test", "Your health is full")
    If @error Then
        Local $findFood = PixelSearch(556, 240, 738, 493, 0xE44C1B, 5)
        If Not (@error) Then
            LC($findFood[0], $findFood[1]) ;this is the thing it only does once I want the checkHealth() function to loop
        EndIf
;~      While ($needrest)
;~      WEnd
    EndIf
EndFunc   ;==>checkHealth

Func myExit()
    MsgBox(0, "Exiting", "The Bot Has Quit")
    Exit
EndFunc   ;==>myExit

Maybe here:
 

While ($needrest)
        WEnd

 

That worked! But now it spam clicks the leftclick here

 

   $findFood = PixelSearch(556, 240, 738, 493,0xE44C1B,5)


   If NOT(@error) Then
      LC($findFood[0],$findFood[1])
      EndIf

Is there a way to change this so it only clicks once?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Maybe:

-snip-

Edited by Jos
You should know better too!

Regards,
 

Share this post


Link to post
Share on other sites

@Vexhero,

Seems you are automating a game when reading through your posted script comments, as that contains terms that will not be used on any regular program.

So please ensure you read our Forum rules first before making a next post!

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.