I have run into a problem that with my current level and understanding I cannot seem to break. I am trying to build a reference of all the colours my mouse pointer captures below it and then logs how many times they exist.
I am trying to get it to come out as an associative array where the colour will be the index and the value will be the number of occurrences.
Problem is when it's any hex number that has a format similar to 0x01212, 0x002231, 0x000123 it will only be logged into the index as 1212, 2231, 123.
I have tried everything I understand, but the result is always the same.
Code: Select all
i :=1
OccNum := 1
target := 25
colourCnt := {}
clipboard :=
while ( i != target +1 ) { ; START
MouseGetPos, TempX1, TempY1
MouseGetPos, TempX2, TempY2
Dis1 := TempX2 -TempX1
TranDis1 := StrReplace(Dis1, "-" , "")
Dis2 := TempY2 -TempY1
TranDis2 := StrReplace(Dis2, "-" , "")
if ( TranDis1 > 0) || ( TranDis2 > 0 )
{
MouseGetPos, CordX, CordY
PixelGetColor, Colour, CordX, CordY, RGB
Colour := StrReplace(Colour, "0x" , "")
if (colourCnt.HasKey(Colour)) {
colourCnt[Colour] := "Occurrences : " OccNum++
} else {
colourCnt[Colour] := "Occurrences : " 1
}
i++
}
} ; END
NewColourCount := {}
for k, v in colourCnt ; Thought this would fix index formatting
{
if ( StrLen(k) = 3 ) {
k := "000" . k
} else if ( StrLen(k) = 4 ) {
k := "00" . k
} else if ( StrLen(k) = 4 ) {
k := "0" . k
} else {
k := k
}
NewColourCount[k] := v
OrigData .= "Colour : " k " " v "`n" ; Only partially fixed, Index name still unchanged
}
For k, v in NewColourCount ;Index names still come out as 1212, 2231, 123 etc
Msgbox % "Key : " k "`nValue : " v
clipboard := OrigData
Msgbox % "Finished"
Return
Heres what the code now looks like after a few revisions.. The data contained in OrigData, shows the formatting correctly when pasted into notepad etc i.e 01212, 002231, 000123 will be outputted.
Any suggestions and or explanations would be immensely appreciated.
Thank you.