AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

blank return when should be true (1) or false (0)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Sun Nov 11, 2007 3:19 pm    Post subject: blank return when should be true (1) or false (0) Reply with quote

The following function always returns 1 or 0:
Code:

/*  Usage:
 *     Searches for the specifed color in the given rectangle of a window capture created from Display_CreateWindowCapture
 *  Parameters:
 *     x, y, w, h: the rectangle parameters to search
 *     color: the color in BGR format or one of:
 *        BlueBackground, BlueForeground, GreenBackground, GreenForeground, RedBackground, RedForeground
 *        CyanBackground, CyanForeground, YellowBackground, YellowForeground, VioletBackground, VioletForeground
 *        DarkBackground, DarkForeground, LightBackground, LightForeground
 *     variation: the allowed variation from the specified color
 *     id: either a window id or the letter c followed by the device context handle as given by Display_CreateWindowCapture
 *        if no id is specified, the Last Found Window will be used.
 *  Return:
 *     Returns true if the specified color/variation is found within the given area, false otherwise.
*/

Display_PixelSearch(x, y, w, h, color, variation = 0, ByRef id = "") {
   Display_GetContext(device, context, pixels, id)
   if color is not integer
      isPixel = Display_%color%
   Loop, %w% {
      j := y
      Loop, %h% {
         bgr := Display_GetPixel(context, x, j++)
         pixel := isPixel ? Display_IsPixel(isPixel, bgr, variation) : Display_CompareColors(bgr, color, variation)
         if pixel {
            if device
               Display_DeleteWindowCapture(device, context, pixels)
            return true
         }
      }
      x++
   }
   if device
      Display_DeleteWindowCapture(device, context, pixels)
   return false
}


Except in this function:
Code:
FullTilt_Process(ByRef seat) {
   local r := false, device, context, pixels, x, y, w, h
   Display_CreateWindowCapture(device, context, pixels)
   local c := "c" . context
   GetWindowArea(x, y, w, h, FullTilt_%seat%)
   WinGetPos, , , w
   local findText := w - 2 * ResizeBorder > 516
   w := Round(w * 33 / 472)
   local chips
   println(seat)
   if InStr(seat, "RT", true) {
      y -= 2*h
      println("light:" . Display_PixelSearch(x, y, w, 2*h, "LightForeground", 0, c))
      println("hi")
      MsgBox, % Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c)
      println("white:" . Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c))
      println("hi")
      if (!Display_PixelSearch(x, y, w, 2*h, "LightForeground", 0, c) && Display_PixelSearch(x, y -= findText ? (h - 2) * 2, w, 1, 0xFFFFFF, 0, c)) {
         if findText {
            x -= h * 3
            local x2 := x + w
            local w2 := w
            Display_FindText(x2, y, w2, h, 0xFFFFFF, 0, context)
            x := x
            w *= 2
            chips := CurrencyToFloat(Display_ReadArea(x, y, w, h, 0xFFFFFF, 0, c, 99))
            println("FindText " . x . " " . y . " " . w " " . h . " " . Display_Signature)
         } else {
            w *= 2
            x -= h * 3
            h := 9
            local x1 := x + w, x2, xp
            Loop {
               x2 := x1
               Loop %w% {
                  bgr := Display_GetPixel(context, x2--, y)
                  if (bgr == 0xFFFFFF)
                     break
               }
               if xp {
                  if (xp - x2 > 2)
                     break
               } else
                  xp := x2
               y++
            }
            y -= h - 2
            chips := CurrencyToFloat(Display_ReadArea(x, y, w, h, 0xFFFFFF, 0, c, Round(h/2)))
            println(x . " " . y . " " . w " " . h . " " . Display_Signature)
         }
      }
   } else {
      y -= h * 2 + (findText ? (h - 2) * 2)
      local bgr := Display_GetPixel(context, x, y)
      if (!Display_IsLight(bgr) && Display_PixelSearch(x, y, w, 1, 0xFFFFFF, 0, c)) {
         if findText {
            x -= h * 3
            local x2 := x + w
            local w2 := w
            Display_FindText(x2, y, w2, h, 0xFFFFFF, 0, context)
            x := x
            w *= 2
            chips := CurrencyToFloat(Display_ReadArea(x, y, w, h, 0xFFFFFF, 0, c, 99))
         } else {
            w *= 2
            x -= h * 3
            h := 9
            local x1 := x + w, x2, xp
            Loop {
               x2 := x1
               Loop %w% {
                  bgr := Display_GetPixel(context, x2--, y)
                  if (bgr == 0xFFFFFF)
                     break
               }
               if xp {
                  if (xp - x2 > 2)
                     break
               } else
                  xp := x2
               y++
            }
            y -= h - 2
            chips := CurrencyToFloat(Display_ReadArea(x, y, w, h, 0xFFFFFF, 0, c, Round(h/2)))
         }
      }
   }
   if (chips != "") {
      local reload := false
      if chips is not number
         reload := true
      if (reload || chips < 100 * FullTilt_GetBlind(true)) {
         FullTilt_Reload()
      }
      r := true
   }
   Display_DeleteWindowCapture(device, context, pixels)
   return r
}


Ignore the fact that there is some repetition in that function, it is incomplete and the first part is just a blueprint (copy of the second part). However I ran into a little snag in cleaning it up.

The problem area code is
Code:
Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c)


The debug messages (MsgBox and println) show the following:

Message box shows a blank message

The println calls show:
Code:
RT1
light:0
hi
hi


As you can see, the line that should read "white1" is completely missing.
That is, it should be:
Code:
RT1
light:0
hi
white:1
hi
Back to top
View user's profile Send private message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Sun Nov 11, 2007 3:30 pm    Post subject: Reply with quote

Here are the executed lines in question:
Code:
145: println("light:" . Display_PixelSearch(x, y, w, 2*h, "LightForeground", 0, c)) 
063: Display_GetContext(device, context, pixels, id) 
086: if !id 
088: if (SubStr(id, 1, 1) = "c") 
089: context := SubStr(id, 2)
092: }
064: if color is not integer
065: isPixel = Display_%color%
066: Loop,%w%
066: {
067: j := y
068: Loop,%h%
068: {
069: bgr := Display_GetPixel(context, x, j++)
044: Return,DllCall("GetPixel", UInt, context, Int, x, Int, y)
070: pixel := isPixel ? Display_IsPixel(isPixel, bgr, variation) : Display_CompareColors(bgr, color, variation)
320: Gosub,%label%
365: isPixel := Display_IsLight(bgr, variation)
192: c := (bgr & 0xff) - variation
193: if (c < 200) 
194: Return,false
366: Return
321: Return,isPixel
071: if pixel 
076: }
068: {
069: bgr := Display_GetPixel(context, x, j++)
044: Return,DllCall("GetPixel", UInt, context, Int, x, Int, y)
070: pixel := isPixel ? Display_IsPixel(isPixel, bgr, variation) : Display_CompareColors(bgr, color, variation)
320: Gosub,%label%
365: isPixel := Display_IsLight(bgr, variation)
192: c := (bgr & 0xff) - variation
193: if (c < 200) 
194: Return,false
366: Return
321: Return,isPixel
071: if pixel 
076: }
068: {
069: bgr := Display_GetPixel(context, x, j++)
044: Return,DllCall("GetPixel", UInt, context, Int, x, Int, y)
070: pixel := isPixel ? Display_IsPixel(isPixel, bgr, variation) : Display_CompareColors(bgr, color, variation)
320: Gosub,%label%
365: isPixel := Display_IsLight(bgr, variation)
192: c := (bgr & 0xff) - variation
193: if (c < 200) 
195: c := ((bgr >> 8) & 0xff) - variation
196: if (c < 200) 
198: c := ((bgr >> 16) & 0xff) - variation
199: Return,c >= 200
366: Return
321: Return,isPixel
071: if pixel 
071: {
072: if device 
074: Return,true
025: Print(str . "
") 
006: if create 
013: {
014: if (str = "") 
018: GuiControlGet,output,99:
019: Gui,99:Show,NoActivate
020: }
021: GuiControl,99:,output,%output%%str%
022: }
026: }
146: println("hi") 
025: Print(str . "
") 
006: if create 
013: {
014: if (str = "") 
018: GuiControlGet,output,99:
019: Gui,99:Show,NoActivate
020: }
021: GuiControl,99:,output,%output%%str%
022: }
026: }
147: MsgBox,Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c) (6.92)
148: println("white:" . Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c)) 
149: println("hi")


It appears the function is not being called.

Edit: appears an incomplete conditional is at fault here. But why does the script not prompt a syntax error instead of blanking out the entire expression?
Back to top
View user's profile Send private message
svi



Joined: 09 Oct 2006
Posts: 124
Location: Finland

PostPosted: Sun Nov 11, 2007 11:37 pm    Post subject: Reply with quote

Xander wrote:
Edit: appears an incomplete conditional is at fault here. But why does the script not prompt a syntax error instead of blanking out the entire expression?

Do you mean that on the right side of the ternary operator (a question mark and a colon) there should be two values / expressions?

On the left side you can use a condition (a > b), or a variable. Or, as curiosity, a constant (0 means false, other values mean true) or a word TRUE or FALSE.

So your strange looking
Code:
isPixel ? ...
is valid.
_________________
Pekka Vartto
Back to top
View user's profile Send private message
Xander



Joined: 23 Sep 2007
Posts: 142

PostPosted: Sun Nov 11, 2007 11:58 pm    Post subject: Reply with quote

The syntax error is in here:
Code:
Display_PixelSearch(x, y - (findText ? (h - 2) * 2), w, 1, 0xFFFFFF, 0, c)

Not the isPixel bit in the Display_PixelSearch function.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group