Sign in to follow this  
Followers 0
BitByteBit

Write Co-Ords to ever expanding array?

8 posts in this topic

#1 ·  Posted (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 by BitByteBit

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 by BitByteBit

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by BitByteBit

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

#8 ·  Posted (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 by KingGeorge

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0