Page 1 of 1

Help with ahk

Posted: 11 Aug 2018, 20:18
by ivyandrei
Hi! I am a beginer and i don't know why my ahk is not working totally. It's going through 1 loop and then nothing.. I tried find something on site to solve this but i don't understand all from them. Please help me and sorry for my english.

Code: Select all

^+r::
looptot:
loop
{
if (Breakloop = 1) {
break
} else {
WinActivate ahk_class Chrome_WidgetWin_1
Send ^1
Scrollloop:
loop
	{
	PixelGetColor, scroll, 1834 , 134, RGB
	If !(scroll = "0x000000")
	break
}
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
Click, 1911, 107
MouseClickDrag, left, 1911, 147, 1916, 211, 0
loopultimele3:
loop
{
PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	one := true
} else {
	one := false
}
PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	two := true
} else {
	two := false
}
PixelSearch, x3, y3, 1376, 265, 1396, 286, 0xFFFFFF, 0, Fast RGB
If (ErrorLevel = 0) {
	three := true
} else {
	three := false
}	
If (one) and (two) and (three) {
	break
}
}
loopurmatoareaculoare:
loop
{
	PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
	if !ErrorLevel {
		break
	sleep, 50
}
}
sleep, 4000
click, 905, 745
sleep, 14000
loopurmatoareaculoare2:
loop
{PixelGetColor, color, 979, 956, RGB
if !(color = "0x3C9649") {
	break
}
}
sleep, 1000
loopdacaediferitderosu:
loop
{
PixelGetColor, color2, 979, 956, RGB
If !(color2 = "0xFF0000") {
loopdubleaza:
loop
{
			sleep, 4000
			click, 1135, 1002
			click, 1135, 1002
			sleep, 14000
			loopverificadacavinerosu:
			loop:
			{
			PixelGetColor, color3, 979, 956, RGB
				If (color3 = "0xFF0000") {
				break
			} else {
				Continue , looptot
			}
}
^+s::
Breakloop = 1
return				

Re: Help with ahk

Posted: 12 Aug 2018, 03:32
by Rohwedder
Hallo,
6 Errors: Missing "}"
Try it with a clean indentation!
https://autohotkey.com/docs/Tutorial.htm#s84

Re: Help with ahk

Posted: 12 Aug 2018, 14:34
by Alibaba
Hello ivyandrei, welcome to the forums!
For your future topics, please try to use more specifical titles. “Help with ahk” is a bit too general for an ahk help forum. ;)

Re: Help with ahk

Posted: 12 Aug 2018, 14:48
by ivyandrei
I modified the script to look better and understand something from it and i solved the problem with the missing "}", but it's not doing what i want. I made this script to play for me at roulette. The site is automatic and it doesn't have a start button so i had to schedule it to wait for the spins. I made him to open my chrome tab and fix the page exactly where i need, then is verifying if the last 3 spins were black and then is waiting for the next spin and if it is black it places bet on red and it it is red, restart the all loop.. If i have more black spins in a row it have to double the bet.. The ahk is only fixing my web page and it's not placing any bet. The "loopifthecolorwillchange" is used where i see what came out this round, i used it because there is coming a black/red/green square with a yellow edge.. Please help me!

Code: Select all

^+r::
loopall:
loop
{
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast3:
		loop
		{
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}
			PixelSearch, x3, y3, 1376, 265, 1396, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				three := true
			} else {
				three := false
			}	
			If (one) and (two) and (three) {
			break
			}
		}	
	loopifblackiscoming:
	loop
	{
		PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
		if !ErrorLevel {
			break
		sleep, 50
		}
	}
	sleep, 4000
	click, 905, 745
	sleep, 14000
				loopifthecolorwillchange:
				loop
				{
					PixelGetColor, color, 979, 956, RGB
					if !(color = "0x3C9649") {
						break
					}	
				}
				sleep, 1000
							loopifiwon:
							loop
							{
								PixelGetColor, color2, 979, 956, RGB
								If (color2 = "0xFF0000") {
									Continue , loopall
								} else {
									sleep, 4000
									click, 1135, 1002
									click, 1135, 1002
									sleep, 14000
									Continue , loopifthecolorwillchange
								} 			
							}
	}
}

^+s::
Breakloop = 1
return				

Re: Help with ahk

Posted: 14 Aug 2018, 13:37
by ivyandrei
Someone know what is the problem?

Re: Help with ahk

Posted: 14 Aug 2018, 14:09
by Xtra
Read here: CoordMode

Re: Help with ahk

Posted: 14 Aug 2018, 18:33
by ivyandrei
Xtra wrote:Read here: CoordMode
Thank you for your suggestion. That went some way, it's not entering looplast3 where it was supposed to verify if the last three numbers were black and then continue, but it's placing bet after 1 black indifferent if the last 3 are black/red/green.

Re: Help with ahk

Posted: 14 Aug 2018, 19:04
by Xtra
Did you set coordmode for mouse and pixel ?

Show your changes.

Re: Help with ahk

Posted: 14 Aug 2018, 20:03
by ivyandrei
I did not understand everything from there. That's the ahk with the changes. It's skipping the looplast2. There is the problem.

Code: Select all

^+r::
loopall:
loop
{
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			CoordMode, Pixel , Screen
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast2:
		loop
		{
			CoordMode, Pixel , Screen
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			CoordMode, Pixel , Screen
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}	
			If (one) and (two) {	
				loopifblackiscoming:
				loop
				{
					CoordMode, Pixel , Screen
					PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
					if !ErrorLevel {
						break
					sleep, 50
					}
				}
				sleep, 4000
				click, 905, 745
				sleep, 14000
							loopifthecolorwillchange:
							loop
							{
								CoordMode, Pixel , Screen
								PixelGetColor, color, 979, 956, RGB
								if !(color = "0x3D9749") {
									break
								}	
							}
							sleep, 1000
										loopifiwon:
										loop
										{
											CoordMode, Pixel , Screen
											PixelGetColor, color2, 979, 956, RGB
											If (color2 = "0xFF0000") {
												Continue , loopall
											} else {
												sleep, 4000
												click, 1135, 1002
												click, 1135, 1002
												sleep, 14000
												Continue , loopifthecolorwillchange
											} 			
										}
		}							
	}
}
}

^+s::Exitapp
return				

Re: Help with ahk

Posted: 14 Aug 2018, 20:07
by Xtra
Put:
CoordMode, Pixel , Screen
and
CoordMode, Mouse, Screen

At the top of the script and remove all the other coordmode references you added.

Try it and see what happens.

Re: Help with ahk

Posted: 14 Aug 2018, 20:55
by ivyandrei
I tried and it's doing the same thing. I posted you a photo of the site to see how it looks.

Code: Select all

^+r::
loopall:
loop
{
	CoordMode, Pixel , Screen
	CoordMode, Mouse, Screen
	if (Breakloop = 1) {
	break
	} else {
	WinActivate ahk_class Chrome_WidgetWin_1
	Send ^1
		Scrollloop:
			loop
			{
			PixelGetColor, scroll, 1834 , 134, RGB
			If !(scroll = "0x000000") {
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				Click, 1911, 107
				MouseClickDrag, left, 1911, 147, 1916, 211, 0
				} else {
				break
				}
			}	
		looplast2:
		loop
		{
			PixelSearch, x1, y1, 1312, 265, 1334, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				one := true
			} else {
				one := false
			}
			PixelSearch, x2, y2, 1343, 265, 1365, 286, 0xFFFFFF, 0, Fast RGB
			If (ErrorLevel = 0) {
				two := true
			} else {
				two := false
			}	
			If (one) and (two) {	
				loopifblackiscoming:
				loop
				{
					PixelSearch, x4, y4, 975, 956, 981, 961, 0x000000, 0, Fast RGB
					if !ErrorLevel {
						break
					sleep, 50
					}
				}
				sleep, 4000
				click, 905, 745
				sleep, 14000
							loopifthecolorwillchange:
							loop
							{
								PixelGetColor, color, 979, 956, RGB
								if !(color = "0x3D9749") {
									break
								}	
							}
							sleep, 1000
										loopifiwon:
										loop
										{
											PixelGetColor, color2, 979, 956, RGB
											If (color2 = "0xFF0000") {
												Continue , loopall
											} else {
												sleep, 4000
												click, 1135, 1002
												click, 1135, 1002
												sleep, 14000
												Continue , loopifthecolorwillchange
											} 			
										}
		}							
	}
}
}

^+s::Exitapp
return				
https://imgur.com/a/PzId9OO

Re: Help with ahk

Posted: 14 Aug 2018, 21:20
by Xtra
When you got all the coords for "everything" you need make sure you used screen coords (aka absolute)

Might be a good time to start using message boxes or tooltips to debug the issue.

Thats about all i can recommend atm.

Re: Help with ahk

Posted: 14 Aug 2018, 22:00
by ivyandrei
Xtra wrote:When you got all the coords for "everything" you need make sure you used screen coords (aka absolute)

Might be a good time to start using message boxes or tooltips to debug the issue.

Thats about all i can recommend atm.
Thank you for your help and for your wasted time. I really appreciate that. Maybe the problem is with “CoorMode, pixel, screen”. Should i use “CoordMode, pixel, window”? I used Mpos/Mousecoord or something like this to found the coordinates for the entire ahk.

Re: Help with ahk

Posted: 14 Aug 2018, 22:27
by Xtra
Whichever you used to get the coordinates and colors is what you need to use for the CoordMode setting.