Jump to content

Why isnt my function looping? [SIMPLE]


Recommended Posts

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

 

Link to comment
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,
 

Link to comment
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?

Link to comment
Share on other sites

  • Developers

@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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...