Another Loop problem for me Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Another Loop problem for me

15 Apr 2021, 14:07

My Script works perfectly for me so far what I want to do now is after the Pixel was found it should Repeat the Loop BUT from now on use the Command Send,{Down} all the time first so it can take the next 'Object' to find the pixel there and if from the 2nd loop the Pixel was found it should repeat the Cycle again but this time with it should use the Command Send,{Down} twice and so on and on.

Is there a Way to maybe say 1 loop was done cuz pixel was found and counter goes up by 1 and everytime the Command Send,{down} just takes the counter as info to move like Counter 23 = Send,{Down 23} times

Do i have to Create a new loop also or could Continue work also with it.

Here is also a short Video what the script should do by Moving down means
https www.youtube.com /watch?v=AxedtcOSfrU Broken Link for safety

Code: Select all

CODE:
settitlematchmode, 2
SetBatchLines, -1
CoordMode, Pixel, Client
#NoEnv
SetKeyDelay, 0, 50



F1::
loop{
IfWinExist, Remote
{
                
                  send,{Enter down}
                  sleep,150             
                  send,{Enter up}
                  sleep,150
                  send,{Enter down}
                  sleep,150            
                  send,{Enter up}
                  sleep,150
                  send,{Enter down}
                  sleep,150             
                  send,{Enter up}
                  sleep,2000
                  
                   
PixelSearch, Px, Py, 988, 227, 990, 229, 0xB83031, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0xB73435, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0xB13434, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x9C3032, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0xB24144, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x912B2D, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x611817, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x7D2A29, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x641B17, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0xA31B1E, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0xAA2D2C, 30, Fast, RGB
if ErrorLevel
  {
  }
else
  {
  break
  }
PixelSearch, Px, Py, 988, 227, 990, 229, 0x71150E, 30, Fast, RGB
if ErrorLevel
  {
  msgbox, No Primal Found
  }
else
  {
  break
  }
}
}     
msgbox, Primal Found in x%Px% y%Py%.     
     
     
                 
Return

F2::
reload
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 14:33

Not sure what you're saying, but I've restructured your code so it's easier to look at than the empty code blocks and stuff. It might help others review it, or myself if you explain what you mean another way.

Code: Select all

CODE:
settitlematchmode, 2
SetBatchLines, -1
CoordMode, Pixel, Client
#NoEnv
SetKeyDelay, 0, 50

F1::
loop{
	IfWinExist, Remote
	{
					
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150            
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,2000
					
					
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xB83031, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xB73435, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xB13434, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x9C3032, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xB24144, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x912B2D, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x611817, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x7D2A29, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x641B17, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xA31B1E, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xAA2D2C, 30, Fast, RGB
		if !ErrorLevel
			break
		PixelSearch, Px, Py, 988, 227, 990, 229, 0x71150E, 30, Fast, RGB
		if ErrorLevel
		msgbox, No Primal Found
		else
			break
	}
}     
msgbox, Primal Found in x%Px% y%Py%.     
     
     
                 
Return

F2::
reload
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 14:43

Oh ok thanks im fairly new to this...

So as u can see im looking for a pixel. When the Condition was found it start the loop again but this time with a different Object to look for. Lets say i have a list with 60 different images And the Images are Changing everytime the loop will take the first image looks for the pixel im looking for if it wasnt found it takes the 1st object again and trys to find it again until it finds the pixel. Sooner or Later the Pixel will apear so the Script is not in a Infinite Loop so it will eventually break out from the loop. When the Pixel will appear it will take the 2nd image that is 1 below the 1st Image and works with this one.
since It found the Pixel at the first picture it Will NOT take the 1st picture again to find the Pixel.

So this is why i think i Need a Syntax to say like .
1st Picture done take now the 2nd picture and start the loop with this one thats why i mean with send down +1 so it goes up to 60 times since i want 60 pictures to look for something
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 14:49

In the Video i did it manually by pressing down since on the first item the pixel was found but i want the script to say like ok im done with the first picture cuz i found it now i take the 2nd picture but i have to go down to take it
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 14:55

I think you're asking for something like this:

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]

for Each, Color in Colors
{					
	loop
		PixelSearch, Px, Py, 988, 227, 990, 229, Color, 30, Fast RGB
	until !ErrorLevel
	MsgBox, Primal Found in x%Px% y%Py%.
}
Note: Just separate Fast RGB with a space, not a comma.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 15:06

this will defintly help to make the code struture smaller but unfortunatly its not solving my problem mb i explained it wrong.

So basiclly the Script takes the first item and Reforges it then it looks for the Pixel cuz by a small chance the Item will change. If it did it will keep the item and takes the next item thats below the first one so i think i definitely need a send,{Down} Command so it will take the Next item. For that case i think i need also a Counter so it will move down by a number of loops solved
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 15:07

what i need now is to add something to the script that does what i want since i want the loop to start again after the problem was solved but doesnt take the same Item again
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:09

Loops have a built-in counter variable named A_Index that represents the iteration number it's currently in, so you can just use that.

I don't know what you mean by taking the Next item. If you need it to do Send, {Down}, just put that in place of the MsgBox.
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:10

Qplshakyz wrote:
15 Apr 2021, 15:07
what i need now is to add something to the script that does what i want since i want the loop to start again after the problem was solved but doesnt take the same Item again
I don't know how you determine the problem was solved. Apparently it's not that the color was found because I thought you described that each color will be found in sequence no matter what. Maybe I misunderstood because I'm honestly not understanding what is supposed to be happening.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 15:27

I used the Msgbox at the end just to see if it would work so far later im gonna remove that part

If i would use send down in that case it would use the top screen again since in the targeted window after it got checked at the right side it will select the top screen again so i have to move down to take the next screen
Attachments
Unbenannt.png
Unbenannt.png (15.66 KiB) Viewed 528 times
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 15:28

the picture explains what it should do after the first screen was done since it will always start at the top again

this is what i mean by it has to move down so thats why i need like a code that remembers that the first screen is done so it wont take it again after it jumped to the top again
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:32

I think I see what you mean. This will send Down the number of times it is through the loop. So the fourth time through, it sends it 4 times.

Code: Select all

Send, {Down %A_Index%}
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 15:41

so but the pixel will not appear in the first loop mb lets say the pixel will appear after 60 trys i dont want that the send command will now go 60 times down it should go down from now by +1
i think the if i would implement the code into it it would go 60 times down if i understood it right but thats not what i want it could be also possible that after 600 times the pixel wont appear so i dont want that he spams 600 times down^^ it should go just down to the next screen and if it found the pixel lets say after 700 cycles it should now go to the third screen and remember after each loop it will start at the top again so i need the script to remember not to take the first or second screen
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:45

No, it won't do it for each time it doesn't appear if you put it in the outer loop because A_Index will reflect the outer loop when you're outside the inner loop:

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]

for Each, Color in Colors
{					
	loop
		PixelSearch, Px, Py, 988, 227, 990, 229, Color, 30, Fast RGB
	until !ErrorLevel
	Send, {Down %A_Index%} ; doesn't matter how many time the above loop took to find it, A_Index is based on the *for* loop only
}
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:49

To be clear, it will send {Down} one time when the color is 0xB83031, two times when the color is 0xB73435, three times when the color is 0xB13434, etc. Where A_Index is used, its value will be based on how many times the for loop has iterated, not the inner loop iterations.
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 15:52

As a demonstration:

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]

for Each, Color in Colors
{
	loop, 100
	{
		ToolTip, % "Inner loop index: " A_Index
		Sleep, 10
	}
	MsgBox, % "Outer loop index: " A_Index
}
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 16:02

but will the Send down command activate before the loop hits place since it has to move down first to take the next screen

it should move down by that number that the pixel was sucesfully founded and that should take then action before the next loop will start to find the pixel

Code: Select all

F1::
loop{
	IfWinExist, Remote
	{
					
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150            
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,2000
imagine the rest of the code above from before
lets say it goes through the whole cycle and founds the pixel

from now on it should go like

Code: Select all

F1::
loop{
	IfWinExist, Remote
	{
					send,{down 1}  ::        from now on it should take the second screen since it will start from the top otherwise if this loop is also sucesfull it should add a +1 or someting like thats since it has to move down 2 times everytime before the search begins since it will start at the top again
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150            
					send,{Enter up}
					sleep,150
					send,{Enter down}
					sleep,150             
					send,{Enter up}
					sleep,2000
User avatar
boiler
Posts: 16900
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 16:12

Qplshakyz wrote: it should move down by that number that the pixel was sucesfully founded and that should take then action before the next loop will start to find the pixel
This is exactly what the code I showed does. After the pixel is found, it sends {Down} the number of times associated with the iteration of the outer loop before it starts the next iteration of the loop starts to find the new pixel color. I don't think you're understanding what {Down %A_Index%} does.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 16:21

ah okay so since i have then

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]
and in pixelsearch varies by 30 it still looks for all the color above but just moves by that number so do i have to add 60 colors since i want the script to move down by a maximum of 60 times
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 16:29

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]

for Each, Color in Colors
{					
	loop
		PixelSearch, Px, Py, 988, 227, 990, 229, Color, 30, Fast RGB
	until !ErrorLevel
	Send, {Down %A_Index%} ; doesn't matter how many time the above loop took to find it, A_Index is based on the *for* loop only
}
so then i implement this code in the outer loop and this should fix my problem? i feel so stupid now :D :crazy:

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 54 guests