Jump to content

Recommended Posts

Posted

As the title suggests, I'm trying to use pixelgetcolor and it's not seeming to work for me, right now I can't put up my code (on my phone going home) but I'll take this time to explain what I'm trying to do.

I'm trying to use pixelgetcolor to spit out a bunch of random colors from specific locations. Right now the code I'm trying to run asks for input and assigns it to some variable, then increments a count. After your done putting in input, it checks the colors of all the pixels you specified, and tells you what they are. Except that for some reason, no matter how I try to store the color of the pixel, it spits out blanks.

I've tried using the same logic as asking for the input, storing each color in a different variable, didn't work (was also super messy) and moved on to using an array to store the colors.

Side note, how can I release variables after I've finished using them? Sometimes my codes have memory leaks when I leave them running and all hell breaks loose

Super side note, just realized I could probably put the input in an array as well maybe?

Posted

Sorry about the double post but here is what I'm working with right now

$count = 0
Func compileStrings()
   $return = ""
   For $i = 0 To ($count - 1)
      $return = $return & "Position: (" & Execute("$place" & $i & "[0]") & ", " & Execute("$place" & $i & "[1]") & ") has the color: " & $color[$i] & @LF
   Next
   Return $return
EndFunc
Do
   $this = InputBox("Give me a position!", "Use the form 'xx, yy' or enter nothing if done.")
   If ($this == "I'm lazy") Then
      Local $place0[2] = [50, 133]
      Local $place1[2] = [198, 335]
      Local $place2[2] = [525, 115]
      Local $place3[2] = [559, 342]
      Local $place4[2] = [766, 528]
      Local $place5[2] = [33, 343]
      Local $place6[2] = [776, 522]
      Local $place7[2] = [82, 304]
      Local $place8[2] = [142, 204]
      Local $place9[2] = [120, 205]
      Local $place10[2] = [682, 307]
      Local $place11[2] = [350, 247]
      Local $place12[2] = [120, 524]
      $count = 12
      MsgBox(0, "Default values have been entered", "If you would like to input more values you can in the next window")
   ElseIf (Not ($this == "")) Then
      ;MsgBox(0, "I saw input!", "Here is what I read: " & $this)
      Execute(Eval("place" & $count) = StringSplit($this, ", ", 1))
      $count += 1
   EndIf
   ;MsgBox(0, "I am done checking your input!", "")
Until ($this == "")
Global $color[$count]
Do
   For $i = 0 To ($count - 1)
      ;MsgBox(0, "Info for i", "i = " & $i)
      $color[$i] = PixelGetColor(Execute("$place" & $i & "[0]"), Execute("$place" & $i & "[1]"))
      ;MsgBox(0, "I just checked (" & Execute("$place" & $i & "[0]") & ", " & Execute("$place" & $i & "[1]") & ")", "It had the color: " & Execute("color[" & $i & "]"))
   Next
      MsgBox(0, "Here is all the info... ALL OF IT!", compileStrings())
      $answer = MsgBox(1, "Continue with same inputs?", "OK for yes, cancel for no")
Until $answer = 2

Also I just fixed my own issue so now the only thing I want to know really is how to release variables and if anyone has any better approaches I'm all ears :D

(and if anyone is interested the problem was:

Execute($color[$i] = PixelGetColor(Execute("$place" & $i & "[0]"), Execute("$place" & $i & "[1]")));the reason for wrapping in an "Execute" was for how I was trying to store the color value before

instead of:

$color[$i] = PixelGetColor(Execute("$place" & $i & "[0]"), Execute("$place" & $i & "[1]"))
Posted

All-In-One 2D Array (example)

Local $array[6][3]
$array[0][0] = 5
$array[1][0] = 50
$array[1][1] = 133
$array[2][0] = 198
$array[2][1] = 335
$array[3][0] = 525
$array[3][1] = 115
$array[4][0] = 559
$array[4][1] = 342
$array[5][0] = 766
$array[5][1] = 528

For $i = 1 To $array[0][0]
    $array[$i][2] = Hex(PixelGetColor($array[$i][0], $array[$i][1]), 6)
    MsgBox(0, '', $i & '  -  ' & $array[$i][2])
Next

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...