BitByteBit 1 Posted November 25, 2009 Share Posted November 25, 2009 (edited) So I get the coordinates from PixelSearch, now I want to save them to an array; easily done: $CoOrd = PixelSearch(Whatever) $Master[0] = $CoOrd [0] $Master[1] = $CoOrd [1] Then when I next time pixelsearch is run, I want to save the coordinates to the next array: $Master[2] = $CoOrd [0] $Master[3] = $CoOrd [1] This should happen until the PixelSearch is @error. How do I go about this? This is what I have so far, but I don't like the method. $Colour = 0xD5DDE5 $Master[2];Create two arrays $Master [0] = 0 ;Assign Values $Master [1] = 0 While $Search = True $CoOrd = PixelSearch(30, 30,@DesktopWidth,@DesktopHeight , $Colour) if not @error then if $Master [0] = 0 then $Master[0] = $CoOrd [0] $Master[1] = $CoOrd [1] Else $Size = UBound($Master) $Max = $Size + 1 $Max1 = $Size + 2 $Master[$Max] = $Coord [0] $Master[$Max1] = $Coord [1] endif else $Search = False endif Wend Thank you all for your time! Edited November 25, 2009 by BitByteBit Link to post Share on other sites
99ojo 0 Posted November 25, 2009 Share Posted November 25, 2009 So I get the coordinates from PixelSearch, now I want to save them to an array; easily done: $CoOrd = PixelSearch(Whatever) $Master[0] = $CoOrd [0] $Master[1] = $CoOrd [1] Then when I next time pixelsearch is run, I want to save the coordinates to the next array: $Master[2] = $CoOrd [0] $Master[3] = $CoOrd [1] This should happen until the PixelSearch is @error. How do I go about this? This is what I have so far, but I don't like the method. $Colour = 0xD5DDE5 $Master[2];Create two arrays $Master [0] = 0 ;Assign Values $Master [1] = 0 While $Search = True $CoOrd = PixelSearch(30, 30,@DesktopWidth,@DesktopHeight , $Colour) if not @error then if $Master [0] = 0 then $Master[0] = $CoOrd [0] $Master[1] = $CoOrd [1] Else $Size = UBound($Master) $Max = $Size + 1 $Max1 = $Size + 2 $Master[$Max] = $Coord [0] $Master[$Max1] = $Coord [1] endif else $Search = False endif Wend Thank you all for your time! Hi, this should work: $Colour = 0xD5DDE5 $Master[2];Create array with 2 elements $Master [0] = 0 ;Assign Values $Master [1] = 0 While 1 $CoOrd = PixelSearch(30, 30,@DesktopWidth,@DesktopHeight , $Colour) if not @error then if $Master [0] = 0 then $Master[0] = $CoOrd [0] $Master[1] = $CoOrd [1] Else ReDim $Master [UBound ($Master) + 2] $Master[UBound ($Master) - 2] = $Coord2 [0] $Master[UBound ($Master) - 1] = $Coord2 [1] endif else ExitLoop endif Wend ;-)) Stefan Link to post Share on other sites
water 2,720 Posted November 25, 2009 Share Posted November 25, 2009 (edited) I would use an 2-dimensional array and resize it every time I need to add new coords. Global $Master[1][2] = [[0, 0]] $Colour = 0xD5DDE5 $CoOrd = PixelSearch(30, 30, @DesktopWidth, @DesktopHeight, $Colour) If Not @error Then ReDim $Master[UBound($Master, 1) + 1][2] ; Resize Array $iElement = UBound($Master, 1) - 1 $Master[$iElement][0] = $CoOrd[0] $Master[$iElement][1] = $CoOrd[1] $Master[0][0] = $iElement ; number of records in the array EndIf NB: I think your script will run in an infinite loop as soon as PixelSearch is successful. You will have to change the search rectangle for PixelSearch as it will always find the first pixel in the array. Edited November 25, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
BitByteBit 1 Posted November 25, 2009 Author Share Posted November 25, 2009 (edited) I would use an 2-dimensional array and resize it every time I need to add new coords. Global $Master[1][2] = [[0, 0]] $Colour = 0xD5DDE5 $CoOrd = PixelSearch(30, 30, @DesktopWidth, @DesktopHeight, $Colour) If Not @error Then ReDim $Master[UBound($Master, 1) + 1][2] ; Resize Array $iElement = UBound($Master, 1) - 1 $Master[$iElement][0] = $CoOrd[0] $Master[$iElement][1] = $CoOrd[1] $Master[0][0] = $iElement ; number of records in the array EndIf NB: I think your script will run in an infinite loop as soon as PixelSearch is successful. You will have to change the search rectangle for PixelSearch as it will always find the first pixel in the array. Thanks for this, I know understand two dimensional arrays. Eventually what I'm searching for will no longer be on the screen so thats not necessary but thanks for the warning ! How do I now write this to .ini using a for loop? For $x = 0 to Ubound($iElement,1) IniWriteSection($Master[$iMax]) IniWriteSection($Master[$iMax1]) Next Edited November 25, 2009 by BitByteBit Link to post Share on other sites
BitByteBit 1 Posted November 25, 2009 Author Share Posted November 25, 2009 (edited) Func Master() $Coord2 = PixelSearch(30, 30,@DesktopWidth,@DesktopHeight , 0xF0F4F9) ReDim $Master[UBound($Master, 1) + 1][2] ; Resize Array $iElement = UBound($Master, 1) - 1 $Master[$iElement][0] = $CoOrd2[0] $Master[$iElement][1] = $CoOrd2[1] $Master[0][0] = $iElement ; number of records in the array _ArrayDisplay($Master) WriteMaster() EndFunc Func WriteMaster() For $r = 0 to UBound($iElement,1) IniWrite("C:\Test.ini","Positions",$Num1,$Master[$iMax][0]) $Num1 = $Num +1 IniWrite("C:\Test.ini","Positions",$Num1,$Master[$iMax][1]) $iMax = $iMax + 1 $Num1 = $Num +1 Next Exit EndFunc On the right tracks right? Edited November 25, 2009 by BitByteBit Link to post Share on other sites
water 2,720 Posted November 25, 2009 Share Posted November 25, 2009 (edited) I would change the Ini-Write function a bit: Func WriteMaster() IniDelete ("C:\Test.ini", "Positions") For $r = 1 To $Master[0][0] IniWrite("C:\Test.ini", "Positions", "X" & $r, $Master[$r][0]) IniWrite("C:\Test.ini", "Positions", "Y" & $r, $Master[$r][1]) Next Return EndFunc ;==>WriteMaster Edited November 25, 2009 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to post Share on other sites
BitByteBit 1 Posted November 25, 2009 Author Share Posted November 25, 2009 Func ReadMaster() $Master = IniReadSection("C:\Test.ini","Positions") _ArrayDisplay($Master) For $r = 1 To $Master [0][0] $y = $r + 1 MsgBox(0,$Master[$r][0],"X: "&$Master[$r][1] & @CRLF & "Y:" & $THEMASTERCOMPLEX[$Y][1]) MouseClick("left",$Master[$R][1],$Master[$Y][1],1) Next Exit EndFunc Why does this click have do an extra click in between clicks? Link to post Share on other sites
KingGeorge 0 Posted November 26, 2009 Share Posted November 26, 2009 (edited) Hi there, please bare with me as this language is new to me, i am more at home with Microsoft VBA, i have looked at your code and banged my head against the wall with 2d arrays. Given my extreme lazyness i have come up with something different. I was thinking, why store the data to a 2d array when you can write the coords straight to the ini file from the PixelSearch loop like this... Func WriteToINIExample() $x = 0 $Search = True Global $CoOrd4[2] Global $CoOrd2[2] $CoOrd4[0] = 0 $CoOrd4[1] = 0 $CoOrd2[0] = 0 $CoOrd2[1] = 0 While $Search = True $CoOrd2 = PixelSearch(30, 30, @DesktopWidth, @DesktopHeight, 0x68540E) If Not @error Then IF $CoOrd2[0] <> $CoOrd4[0] then MouseClick("Left", $CoOrd2[0], $CoOrd2[1], 1, 0) $x = $x + 1 IniWrite("C:\Test.ini", "Positions", "X" & $x, $Coord2[0]) IniWrite("C:\Test.ini", "Positions", "Y" & $x, $Coord2[1]) $CoOrd4[0] = $CoOrd2[0] Else Sleep(1) EndIf Else MsgBox(0,"","Jumped out") Sleep(1700) $Search = False EndIf WEnd EndFunc I was also thinking probably due to my lazyness that to avoid the 2d array when reading the ini data you could use a For/Next loop with a step of 2 like this... Func ReadMaster() $Master = IniReadSection("C:\Test.ini","Positions") For $x = 1 To UBound($Master)-1 step 2 MouseMove($Master[$x][1],$Master[$x+1][1],1) Next EndFunc I hope this helps as i found it much easier to understand Edited November 26, 2009 by KingGeorge Link to post Share on other sites
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now