Another Loop problem for me Topic is solved

Ask gaming related questions (AHK v1.1 and older)
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 17:16

Qplshakyz wrote: 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
Yes, if you put 60 colors in the array, it will find the first color then press Down once before it starts the loop again and looks for the next color, then it finds the second color then presses Down twice, and so on until it reaches the last color and it will find that and press Down 60 times. The command Send, {Down 20} sends the down key 20 times, which is why Send, {Down %A_Index%} sends Down the number of times equal to the value of A_Index. And A_Index is the built-in loop counter. Each loop (the inner one and the outer one) have their own version of A_Index, so one doesn't affect the other.

Qplshakyz wrote: so then i implement this code in the outer loop and this should fix my problem? i feel so stupid now :D :crazy:
That code is both loops. It already contains both an outer loop and an inner loop. You don't put it inside another loop. See the comments in the code below:

Code: Select all

; put as many colors as you want in the array below and that will determine how many times the outer loop executes (once for each color)
Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]

for Each, Color in Colors ; this is the outer loop.  for each iteration of the loop, it selects the next color in the array
{					
	loop ; this is the inner loop. it keeps looping until the color is found
		PixelSearch, Px, Py, 988, 227, 990, 229, Color, 30, Fast RGB
	until !ErrorLevel ; this ends the inner loop when the color is found
	Send, {Down %A_Index%} ; this sends {Down 1} the first time through the outer loop, then {Down 2} the second time, and so on
}
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 17:32

the field i was looking for is a 3x3 pixel so in total 9 colors and unfortunatly i cannot put 60 colours inside or make the range of the pixel bigger i did so many colours since i though i have a higher chance to find it
so lets say if i pixelsearch would try to find only one pixel with 1 specific colour that varies by 30 what would you recommend me in that case since all the colours will be pretty much the same i couldnt put then in a_index so many
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 17:33

and btw thank you so much for your patience and help im so thankful that u provide me with so much info
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 17:36

and i forgot to mention at all the images that i want to find the pixel the colour will be pretty much the same , sometimes with small variation so theres the possibility that at the second image there could also be the same colour code on the first a_index

Could i repeat the same colour code on a_index like 60 times
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 17:44

Qplshakyz wrote: the field i was looking for is a 3x3 pixel so in total 9 colors and unfortunatly i cannot put 60 colours inside or make the range of the pixel bigger i did so many colours since i though i have a higher chance to find it
so lets say if i pixelsearch would try to find only one pixel with 1 specific colour that varies by 30 what would you recommend me in that case since all the colours will be pretty much the same i couldnt put then in a_index so many
I'm not sure I understand. You can use ImageSearch to look for a 3x3 image, but you would have to capture each of the images to use as a reference for the command.

Qplshakyz wrote: and btw thank you so much for your patience and help im so thankful that u provide me with so much info
You're welcome. I'm happy to help, especially if you're learning how to code better.

Qplshakyz wrote: and i forgot to mention at all the images that i want to find the pixel the colour will be pretty much the same , sometimes with small variation so theres the possibility that at the second image there could also be the same colour code on the first a_index
Then in sounds like you shouldn't use a variation of 30, but you should be trying to match more exactly. Perhaps the use of ImageSearch would change what you need to do. I'm still not sure I understand your goal.

Qplshakyz wrote: Could i repeat the same colour code on a_index like 60 times
If you're going to keep the color the same, there's a much easier way to do that than to have an array with 60 colors. You would just loop 60 times:

Code: Select all

loop, 60
{					
	loop
		PixelSearch, Px, Py, 988, 227, 990, 229, 0xB83031, 30, Fast RGB
	until !ErrorLevel
	Send, {Down %A_Index%}
}
I'm not sure finding the same color 60 times in a row makes sense to me, but I guess you know what you're trying to do. I suppose you're saying that eventually the same color (almost) appears every time.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 18:19

So basiclly its a Rolling Scripts that keeps rolling until Condition is found all the Items are gonna get this Red Border but it seems like sometimes they are the same and sometimes they have a small difference.
Thats why i took a 3x3 Pixel and took all the Colours that were in that 3x3

And like i showed from the picture before it Takes the Top Item throws it to the Right side to Upgrade it and does it an infinite amount of time until it finds that red Border and when it did then it should jump down to the second Item thats why after the first loop was sucessful it moves down by 1


The Script that i Provided does the first phase of Upgrading Pretty good atm it stops when it finds the Red Border but now it should take the next item thats sitting Below the Sucesfully founded one and keeps trying until the Condition was found there

Thats also the Reason finding 60 times the same or close colour since im looking for that specific State of an Item#

My Goal is that the Script understands after the State was found it should move to the next Item by moving down and skip the sucesfully upgraded ones. A_Index could be helpful for sure here but all the Colours of the Items are gonna be same or close i couldnt figure out how to use it now.
Attachments
Unbenannt.png
Unbenannt.png (574.46 KiB) Viewed 468 times
Last edited by Qplshakyz on 15 Apr 2021, 18:55, edited 1 time in total.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 18:54

I’m not sure what sending Down does and why it makes sense to increase how many times you send it each time through the loop. I thought it was because you’re selecting the next image in a series of images on the left. If that’s true, will there be 60 images? I’m sure I’m missing something about why you’re sending Down.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 19:01

Well not like 60 Images but The Character ingame can have in the Inventory up to 60 Items and you can scroll down 60 Times.
So lets say i throw the second item Manually to the Right Side to Upgrade it when i want to select the same item again i have to move down since i will start at the top again so everytime i want to upgrade the Second item it forces mekinda to move down once to select it again
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 19:07

By what u said what a_index does it seems kinda to fit but somehow also not

The 9 Colours that i Selected are those that i want to look for and it seems like if the First colour was found it would move down second colour twice etc but im still looking for the same colours anyway so it shouldnt work kinda isnt it?
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 19:38

https://youtu.be/LUaeK_I3HAI

here in the Video you can see i can Scroll down by alot. Everything i did was manually. I took the 3rd Item threw it to the right side and waite to get to that State i mentioned after the Upgrade was done i had to scroll down again to take the 3rd Item again and so on. You can also see where i took the 6th Item and did the same and as you can see after the Upgrade i end up at the Top and have to scroll down again and this is where the script should Realise after the Spefic Criteria was Found it should move down to the next Item. This is what i ment by send Down
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 19:43

So basicly if i would use this only it would probably work perfectly up to 9 times but i want to do this up to 60 times if you can understand

Code: Select all

Colors := [0xB83031, 0xB73435, 0xB13434, 0x9C3032, 0xB24144, 0x912B2D, 0x611817, 0x7D2A29, 0x641B17, 0xA31B1E, 0xAA2D2C, 0x71150E]
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me

15 Apr 2021, 19:53

It sounds like sending down that many times makes sense. You can send many more times than 9. You can send as many as it needs. If there are 60 items, you could put 60 colors in the list and it will send Down that many times.
Qplshakyz
Posts: 35
Joined: 13 Apr 2021, 12:07

Re: Another Loop problem for me

15 Apr 2021, 20:08

So Even if the Colour will be the same since its the specific State im looking for i could actually just repeat the color code isnt it?

I will test everything tomorrow my head is burning already :D
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Another Loop problem for me  Topic is solved

15 Apr 2021, 20:09

Yes, you could just repeat the color in the list.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: CrowexBR and 81 guests