Sign in to follow this  
Followers 0
Astro66

Loop in a infinate Loop problem

14 posts in this topic

Since the change and removal of goto-label ect. has me a little confused on how to make a loop in an endless loop.

so what i want to do the following:

Global $pixel = 5921370

Global $pixel2 = 3773968

Global $pixel3 = 7671057

While True

;here<------------------------------------------------

If PixelGetColor(820,524) = $pixel2 Then -

MouseClick("left",820,524,1) -

If PixelGetColor(820,524) = $pixel3 Then -

MouseClick("left",697,652,1) -

If PixelGetColor(482,144) = $pixel Then -

; goto --------------------------------------------------

EndIf

EndIf

EndIf

WEnd

as long as pixel is grey i want it to keep looping till it changes color and checking 2 other pixels.

I am lost on how to loop back if anyone can help please.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Shouldn't it be already looping?

Your while loop is infinite, that's for sure.

While in loop, if color Pixel 2 is found, then it clicks and then looks for color pixel 3, if it finds it, then it looks for your last color pixel, if it finds it then end if, all the instructions in the while loop will be over and it will start over.

What your construction does though is that if what you're looking for isn't 100% going to be there, and your first if ($pixel2) falls off, it's gonna start looping back on the first step.

As a proof of concept of it working:

Global $test = 0
Global $test1 = 0
Global $test2 = 0
hotkeyset("1","Test")
hotkeyset("2","Test1")
hotkeyset("3","Test2")
hotkeyset("4","Test4")
While True
If $test=1 Then
msgbox(0,"0","0")
if $test1=1 then
   msgbox(0,"1","1")
  if $test2=1 Then
    msgbox(0,"2","2")
EndIf
EndIf
EndIf
WEnd
func Test()
$Test=1
EndFunc
func Test1()
$Test1=1
EndFunc
func Test2()
$Test2=1
EndFunc
func test4()
$test=0
EndFunc
Edited by Elku

Share this post


Link to post
Share on other sites

I v read this 5 times and i still fail to understand

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Oh i forgot i have other code in the loop i need that part to continue looping while the pixel on last check is grey back to the ;here label

There is other code after the while true but it works fine its the loop at the end that i can't fiqure out:

If PixelGetColor(482,144) = $pixel Then goto ;here (program detects grey pixel i need it to loop back to ;here)

there is also code after endif but that is working fine as well for some reason while it 's checking pixel and its grey it continues to execute code between

while true and ;here.

Global $pixel = 5921370

Global $pixel2 = 3773968

Global $pixel3 = 7671057

While True

;other code here

;loop

If PixelGetColor(820,524) = $pixel2 Then

MouseClick("left",820,524,1)

If PixelGetColor(820,524) = $pixel3 Then

MouseClick("left",697,652,1) -

If PixelGetColor(482,144) = $pixel Then

goto ;loop

WEnd

Edited by Astro66

Share this post


Link to post
Share on other sites

What your construction does though is that if what you're looking for isn't 100% going to be there, and your first if ($pixel2) falls off, it's gonna start looping back on the first step.

Yes that is what im trying to avoid how do i code it to avoid that?.

Share this post


Link to post
Share on other sites

Either make sure that each condition will be fulfilled (Add sleep timers if you're in an online game, lag will cause delay).

You could add another while with a variable that you switch.

While True
;other code here

$switch = false

While $Switch = false
If PixelGetColor(820,524) = $pixel2 Then
MouseClick("left",820,524,1)
If PixelGetColor(820,524) = $pixel3 Then
MouseClick("left",697,652,1) -
If PixelGetColor(482,144) = $pixel Then
Else $Switch = true
Else $Switch = true
Else $Switch = true
Endif
Endif
Endif
Wend
WEnd

Not the most optimal code, but here the first while loop is infinite, no need to explain further.

;other code here
$switch = false

It will then run your initial code and set $switch to false, which will initiate your second loop.

While $Switch = false
If PixelGetColor(820,524) = $pixel2 Then
MouseClick("left",820,524,1)
If PixelGetColor(820,524) = $pixel3 Then
MouseClick("left",697,652,1) -
If PixelGetColor(482,144) = $pixel Then
Else $Switch = true
Else $Switch = true
Else $Switch = true
Endif
Endif
Endif
Wend

In this second loop, I added elses. That means that if any of them fails, it will set $switch to true, and exit the while loop, which is what I assume you want the program to do. As long as it detects everything you're looking for, it's just looping over and over and over, if it fails to do so, it will run all the code over again.

Share this post


Link to post
Share on other sites

I get the following error:

: ==> Illegal text at the end of statement (one statement per line).:

Else $Switch = true

Else ^ ERROR

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Maybe you all could start with checking the helpfile for the proper syntax options of If....elseIf....else....endif.

While doing your research make sure you also check our forum rules!

Jos

Edited by Jos

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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What Jos said , I haven't coded in forever and I did it slightly wrong:

It should go something like

Else
$Switch = true
Endif
Else
$Switch = true
endif
Else
$Switch = true
Endif
Edited by Elku

Share this post


Link to post
Share on other sites

Ahh i get now i have made changes to program now it works, i have been trying to learn autoit to automate my work as a computer tech overnight this program automates a hard drive scan looking for errors and pressing the fix button it works now thanks for the help,

So far i have automated hard drive scan->rootkit scan->virus malware scan->tuneup->create logs.

It been years since i have done programming i started out with basic->6502 asm->c->c++.

Is there such a thing as a debugger for autoit im so use to looking for bugs that way so i can see what is going on.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

What Jos said , I haven't coded in forever and I did it slightly wrong:

It should go something like

Else
$Switch = true
Endif
Else
$Switch = true
endif
Else
$Switch = true
Endif

You are sure you found this in the Helpfile as valid syntax? Edited by Jos

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

Share this post


Link to post
Share on other sites

Is there such a thing as a debugger for autoit im so use to looking for bugs that way so i can see what is going on.

Not really. You can sprinkle

ConsoleWrite($string)

Throughout the code if you're using SciTE. It'll output stuff to the lower window frame so you can trace what's going on.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

I took a look around in the example scripts there are a few debuggers there odd though one would think there would be one built into SciTE by now as an official function, maybe something to look into for a future update.

The example scripts area is quite large takes quite a while to look through.

Share this post


Link to post
Share on other sites

you can try something like: (untested)

Global $pixel = 5921370
Global $pixel2 = 3773968
Global $pixel3 = 7671057
;other code here
While True
  If PixelGetColor(820,524) = $pixel2 Then
    MouseClick("left",820,524,1)
    If PixelGetColor(820,524) = $pixel3 Then
      MouseClick("left",697,652,1)
      If PixelGetColor(482,144) = $pixel Then
        ContinueLoop
      EndIf
    EndIf
  Endif
;other code here
Wend

or

Global $pixel = 5921370
Global $pixel2 = 3773968
Global $pixel3 = 7671057
$found = False
While True
  If ($found = False) Then
    ;other code here
  EndIf
  $found = False
  If PixelGetColor(820,524) = $pixel2 Then
    MouseClick("left",820,524,1)
    If PixelGetColor(820,524) = $pixel3 Then
      MouseClick("left",697,652,1)
      If PixelGetColor(482,144) = $pixel Then
        $found = True
      EndIf
    EndIf
  Endif
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