Ending Loop When found Pixel Color

Recommended Posts

Hello i Have HP Bar in my game and it has 170px of width and then im gonna find start of this by mouse pos then i got \$hpStart[0] = 661  \$hpStart[1] = 230 ,  \$hpEnd[0] = 839

And there is from \$hpStart[0] = 661 the same color - 0xCB423B but depends of my points of hp for example on pixel  \$hpStart[0] = 745 would be another color not  0xCB423B and then i will know my my character got 50% of health points.

I encountered problem here - for loop still looping to 839 and not founding this change in color for example on pixel \$hpStart[0] = 745

I would know actual \$i counter and \$hpEnd[0] then only i can calculate current health percent value

```Func MouseCord()
\$MousePos = MouseGetPos()
global \$hpStart = \$MousePos
global \$hpEnd = \$hpStart
\$hpEnd[0] = \$hpEnd[0] + 170

For \$i = \$hpStart[0] To \$hpEnd[0] ; Looping from 661 to 839
\$pixel = PixelGetColor(\$i,\$hpStart[1])
If \$pixel <> 0xCB423B Then
\$hpNowPer = ( \$hpEnd[0] - \$i ) / 170
\$hpPoOdjeciu = 1 - \$hpNowPer
\$hpNowPercent = Round(\$hpPoOdjeciu,2)
ExitLoop ; - that not working
EndIf
Next
EndFunc```

Share on other sites

@Szmycu you come back after 24 hours off and immediately post again regarding a game. As you're obviously not interested in following the forum rules, we are not interested in your company.

√-1 2^3 ∑ π, and it was delicious!

Share on other sites
This topic is now closed to further replies.

• Similar Content

• By MrCheese
Hi guys,

Wondering, is there a better way, likely to use 'for...next' to add a letter to each range, by moving right -> along a range of columns in excel.
I currently use this, but its clunky.
If \$run = 1 Then \$range = "B6:B41" If \$run = 2 Then \$range = "C6:C41" If \$run = 3 Then \$range = "D6:D41" If \$run = 4 Then \$range = "E6:E41" If \$run = 5 Then \$range = "F6:F41" If \$run = 6 Then \$range = "G6:G41" If \$run = 7 Then \$range = "H6:H41" If \$run = 8 Then \$range = "I6:I41" If \$run = 9 Then \$range = "J6:J41" If \$run = 10 Then \$range = "K6:K41" If \$run = 11 Then \$range = "L6:L41" If \$run = 12 Then \$range = "M6:M41" If \$run = 13 Then \$range = "N6:N41" If \$run = 14 Then \$range = "O6:O41" If \$run = 15 Then \$range = "P6:P41" If \$run = 16 Then \$range = "Q6:Q41" If \$run = 17 Then \$range = "R6:R41" If \$run = 18 Then \$range = "S6:S41" If \$run = 19 Then \$range = "T6:T41" If \$run = 20 Then \$range = "U6:U41" If \$run = 21 Then \$range = "V6:V41" If \$run = 22 Then \$range = "W6:W41" If \$run = 23 Then \$range = "X6:X41" If \$run = 24 Then \$range = "Y6:Y41" If \$run = 25 Then \$range = "Z6:Z41" If \$run = 26 Then \$range = "AA6:AA41" If \$run = 27 Then \$range = "AB6:AB41" If \$run = 28 Then \$range = "AC6:AC41" If \$run = 29 Then \$range = "AD6:AD41" If \$run = 30 Then \$range = "AE6:AE41" If \$run = 31 Then \$range = "AF6:AF41" If \$run = 32 Then \$range = "AG6:AG41" If \$run = 33 Then \$range = "AH6:AH41" If \$run = 34 Then \$range = "AI6:AI41" If \$run = 35 Then \$range = "AJ6:AJ41" If \$run = 36 Then \$range = "AK6:AK41" If \$run = 37 Then \$range = "AL6:AL41" If \$run = 38 Then \$range = "AM6:AM41" If \$run = 39 Then \$range = "AN6:AN41" If \$run = 40 Then \$range = "AO6:AO41" If \$run = 41 Then \$range = "AP6:AP41" If \$run = 42 Then \$range = "AQ6:AQ41" If \$run = 43 Then \$range = "AR6:AR41" If \$run = 44 Then \$range = "AS6:AS41" If \$run = 45 Then \$range = "AT6:AT41" If \$run = 46 Then \$range = "AU6:AU41" If \$run = 47 Then \$range = "AV6:AV41" If \$run = 48 Then \$range = "AW6:AW41" If \$run = 49 Then \$range = "AX6:AX41" If \$run = 50 Then \$range = "AY6:AY41"
Normally, if it was going down the rows, i'd use this:

For \$i = 0 To UBound(\$iRowCount) - 1 \$row = \$i + 1 \$range = "B"&\$row&":B"&\$row+1 Next
so something like this, but i don't know how to code sequential columns:
For \$i = 0 To UBound(\$iColCount) - 1 \$col = \$i + 1 \$range = \$col&"1:"&\$col&"40" Next
If I don't make sense, let me know.
Any help would be great. thanks
• By KING_NK
Global \$x=0
Global \$y=0
Func Start()
While 1
AutoItSetOption('MouseCoordMode',0)
AutoItSetOption('SendKeyDelay',10)
WinActivate('XXX')
MouseClick('Primary',852,62,1,10)
sleep(2200)
MouseClick('Primary',880,196,1,10)
Send('260',0)      -----------------------> \$a as 260
MouseClick('Primary',880,196,1,0)
sleep(2200)
MouseClick('Primary',1019,194,1,10)
Sleep(2200)
Send('98',0) ------------------------->\$b as 98
sleep(1000)
Wend
EndFunc

I want to use Different number in every loop in the place of \$a and  \$b.
Is it possble?If it possible Kindly help me
• By amphoric
Hi,
I am struggling converting my 1D array to a 2D array and then showing that in my List View. Below is my current code, where I would like to take the array from the input box, and have that displayed as a list within the list view this is a list of computer names, and then update the 2nd column of each line once I have ran a ping and a registry change on each computer name, with either 'Completed' and 'Failed'
I have checked out the AutoIt Arrays page here: https://www.autoitscript.com/wiki/Arrays , but unfortunately I cannot get my head around it. Any help would be greatly appreciated.
I hope this makes sense.
Thanks

• By RHolmes
I have a program that has a control that changes color a few seconds into running. So ideally, I would poll this to tell when an event has occurred.
I can't seem to retrieve the correct color value for a control. It always seems to return white indicating that its selecting somewhere else in the window.
In the PixelGetColor call I'm adding half the width to the x value and subtracting half the height to the y value  in order to get the center of the control. (assuming the coords returned by ControlGetPos are top left - which i can't be sure of) But I've also tried without modifying the x/y and with changing the PixelCoordMode option to 2. Maybe I'm making a silly mistake and can't see it? Any help would be appreciated.
Code is below:
Opt("PixelCoordMode", 0)
FileChangeDir( "C:\Where\My\File\Is" );
Run( "MyProgram.exe" )
Local \$hClient = WinWaitActive( \$CLIENT_TITLE, "", 10 )
Local \$systemIndicatorClassNN= "[CLASS:Qt5QWindowIcon; INSTANCE:99]"
Local \$hSystemIndicator = ControlGetHandle ( \$hClient, "", \$systemIndicatorClassNN)
Local \$xywh = ControlGetPos ( \$hClient, "", \$hSystemIndicator )
For \$i = 10 To 1 Step -1
\$color = PixelGetColor ( \$xywh[0] + (\$xywh[2]/2), \$xywh[1] - (\$xywh[3]/2), \$hClient )
LogToFile( \$color )
Sleep( 2000 )
Next
• By 0Ethan0
Ahoy Autoit Community!
After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution
The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
The Setup: GUI with a ListView Control and a simple exit button.
The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
The Code (stripped and simplified as much as I could):
#include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global \$c=0 Global \$ssGDI[3], \$ssGraphic[2], \$ssImage Global Const \$bg_color = "000000" Global Const \$ssW = 480, \$ssH = 320 Global \$aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", \$FLTAR_FILES, \$FLTAR_NORECUR ,\$FLTAR_SORT ,\$FLTAR_FULLPATH ) \$guiW = 1200 \$guiH = 726 \$mainWindow = GUICreate("Slideshow Viewer", \$guiW, \$guiH, -1, -1, \$WS_POPUP) \$Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent(\$Button1, "_Exit") \$Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent(\$Button1, "Test") Global \$ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth (\$ListView, 0, 100) _GUICtrlListView_SetColumnWidth (\$ListView, 1, 100) GUICtrlSendMsg(\$ListView, \$LVM_SETEXTENDEDLISTVIEWSTYLE, \$LVS_EX_GRIDLINES, \$LVS_EX_GRIDLINES) GUICtrlSendMsg(\$ListView, \$LVM_SETEXTENDEDLISTVIEWSTYLE, \$LVS_EX_FULLROWSELECT, \$LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", \$ListView) GUICtrlCreateListViewItem("Name 2|Category 2", \$ListView) screenshotWidgetInit(\$ssW,\$ssH, 690, 100) GUISetState(@SW_SHOW, \$mainWindow) GUIRegisterMsg(\$WM_NOTIFY, "WM_Notify_Events") While 1 \$nMsg = GUIGetMsg() Switch \$nMsg Case \$GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For \$k = 1 To UBound(\$aFiles) - 1 screenshotWidgetTransition(\$aFiles[\$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events(\$hWndGUI, \$MsgID, \$wParam, \$lParam) #forceref \$hWndGUI, \$MsgID, \$wParam Local \$tagNMHDR, \$event, \$hwndFrom, \$code \$tagNMHDR = DllStructCreate("int;int;int", \$lParam) If @error Then Return \$event = DllStructGetData(\$tagNMHDR, 3) Select Case \$wParam = \$ListView Select Case \$event = \$NM_CLICK ListView_Click () Case \$event = \$NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return \$GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition(\$image, \$delay = 0, \$speed = 1, \$sleep = 2000) Local \$a, \$d = \$c, \$iX, \$iY \$ssImage = _GDIPlus_ImageLoadFromFile(\$image) \$iX = _GDIPlus_ImageGetWidth(\$ssImage) \$iY = _GDIPlus_ImageGetHeight(\$ssImage) \$FDesktop=\$ssH/\$ssW \$Fact =1 If \$iX > \$ssW And \$FDesktop > (\$iY/\$iX) Then \$Fact=\$ssW/\$iX ElseIf \$iY > \$ssH Then \$Fact=\$ssH/\$iY EndIf \$H1 = Round((\$Fact * \$iY),0) \$W1 = Round((\$Fact * \$iX),0) _GDIPlus_GraphicsDrawImageRect(\$ssGraphic[\$d], \$ssImage,(\$ssW - \$W1)/2, (\$ssH - \$H1) / 2,\$W1,\$H1) WinSetTrans(\$ssGDI[\$d], "", 0) WinSetOnTop(\$ssGDI[\$d], "", 1) For \$a = 0 To 254 Step \$speed WinSetTrans(\$ssGDI[\$d], "", \$a) Sleep(\$delay) Next WinSetTrans(\$ssGDI[\$d], "", 254) WinSetOnTop(\$ssGDI[Not (\$d)], "", 0) WinSetTrans(\$ssGDI[Not (\$d)], "", 0) _GDIPlus_GraphicsClear(\$ssGraphic[Not (\$d)]) \$c = 1 - \$d _GDIPlus_ImageDispose (\$ssImage) ; very important to realease the pics Sleep(\$sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit(\$ssW,\$ssH,\$ssX,\$ssY) \$ssGDI[2] = GUICreate("", \$ssW, \$ssH, \$ssX, \$ssY, \$WS_POPUP, \$WS_EX_MDICHILD, \$mainWindow) \$ssGDI[0] = GUICreate("", \$ssW, \$ssH, 3, 3, \$WS_POPUP, \$WS_EX_MDICHILD, \$ssGDI[2]) \$ssGDI[1] = GUICreate("", \$ssW, \$ssH, 3, 3, \$WS_POPUP, \$WS_EX_MDICHILD, \$ssGDI[2]) ; GUISetBkColor("0x" & \$bg_color, \$ssGDI[2]) GUISetState(@SW_SHOW, \$ssGDI[2]) GUISetState(@SW_SHOW, \$ssGDI[0]) GUISetState(@SW_SHOW, \$ssGDI[1]) WinSetTrans(\$ssGDI[0], "", 0) WinSetTrans(\$ssGDI[1], "", 0) _GDIPlus_Startup() \$ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND(\$ssGDI[0]) \$ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND(\$ssGDI[1]) _GDIPlus_GraphicsClear(\$ssGraphic[0], "0xFF" & \$bg_color) _GDIPlus_GraphicsClear(\$ssGraphic[1], "0xFF" & \$bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose(\$ssImage) _GDIPlus_GraphicsDispose(\$ssGraphic[0]) _GDIPlus_GraphicsDispose(\$ssGraphic[1]) GUIDelete(\$ssGDI[0]) GUIDelete(\$ssGDI[1]) GUIDelete(\$ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?