Jump to content

coordinate color variable dont work if it is set as variable!

Recommended Posts

Posted (edited)

I find it very weird:
if I run like this:
     Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, '0xFF455E')

works fine!

If I run like this:
    Local $metaColor1 = '0xFF455E' or like this Local $metaColor1 = "0xFF455E" or Local $metaColor1 = "'0xFF455E'"
    Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $color)

it doesn't want to work! So something with variable is not working and yes if I print it out like this:
ConsoleWrite(@LF & $posX & ":"& $posY & ":"& $sizeX & ":" & $sizeY & ":" & $color&@LF)

So I dont see the problem, maybe some of you people?

Edited by Daka

Share this post

Link to post
Share on other sites

Maybe you should use $metaColor1 instead of $color in the PixelSearch?

If that was a typo, then try it without the quotes, because it's a number not a string.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post

Link to post
Share on other sites

I was hoping for typo, but it is not. Next code calls function:

Local $metaColor1 = 0xFF455E
   ;check if meta therapy button is availible, visible?
   If ControlCommand("[CLASS:TFormResearchGR]", "", "[CLASS:"& $btn_meta_class &"; INSTANCE:"& $btn_meta_instance &"]", "IsVisible", "") Then
      dump("$btn_metaVisible is visible"&@LF)
      $btn_metaVisible = True
      ;if meta therapy button visable, then check if meta therapy button is green and red if good connection is with headphone
      $image_path = "images\meta-therapy-green-red.bmp"
      $text = "meta therapy button not green"
      ;dump("this is text"& $text & @LF)
      $buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, $metaColor1, False, True, $image_path, $text)
      dump("Activated meta button: " & $buttonActivated1)

And in that function, I call: PixelSearch and if I set the sting in this function like:
$metaColor1 = 0xFF455E and set that then it works, but if I set it before when calling function it doens not wont to work. This is weird. And if I Consolewrite it, string (number) is there :(

Func ifButtonActivated($window, $button, $instance, $metaButtonColor, $click = True, $msgBoxShow = True, $image_path = False, $text = False, $litoPhyto = False)
   ConsoleWrite(@LF & "function ifButtonActivated: " & @LF)
   ConsoleWrite("$window:" & $window &" $button: "& $button &" $instance: "& $instance &" $color: "& $metaButtonColor &@LF)
   ConsoleWrite('$image_path: '& $image_path & @LF)
   Local $buttonActivated = False
   Local $buttonCanceled = False
   Local $buttonNotActivated = False
   ;because even if you bioconnector is inbetween time connected the red button will not appear
   ;so we need to loop again
   Local $litoPhytoActivated = False
   ConsoleWrite($window & @LF)
   ConsoleWrite($button & @LF)
   ConsoleWrite($instance & @LF)

   ;if button exists, research button dont exists
      If ControlCommand($window, "", "[CLASS:"& $button &"; INSTANCE:"& $instance &"]", "IsEnabled", "") Then
    ConsoleWrite($window & "[CLASS:"& $button &"; INSTANCE:"& $instance &"]IsEnabled" & @LF)
         $aPos = ControlGetPos($window, "", "[CLASS:"& $button &"; INSTANCE:"& $instance &"]")
     ConsoleWrite("$aPos[2]" & $aPos[2] & @LF)
     ConsoleWrite("$aPos[3]" & $aPos[3] & @LF)
         $sizeX = $aPos[0] + $aPos[2] + 72
         $sizeY = $aPos[1] + $aPos[3]
     $posX = $aPos[0] + 72
     $posY = $aPos[1]

         ConsoleWrite("$posX:" & $posX & "$posY:" & $posY & "$sizeX" & $sizeX & "$sizeY:" & $sizeY & "$color" & $metaButtonColor &@LF)

         ; Find a pure red pixel in the range 0,0-20,300
     ConsoleWrite(@LF & $posX & ":"& $posY & ":"& $sizeX & ":" & $sizeY & ":" & $metaButtonColor&@LF)

     ConsoleWrite($metaButtonColor& @LF)
     ConsoleWrite(Int($metaButtonColor)& @LF)
         ;Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $color)
     $metaColor1 = 0xFF455E
     ConsoleWrite($metaColor1& @LF)
     ConsoleWrite(Int($metaColor1)& @LF)
     Local $aCoord = PixelSearch($posX, $posY, $sizeX, $sizeY, $metaButtonColor)


Share this post

Link to post
Share on other sites

This is very weird, if I pass it to function the number is there, but Pixelcoordinate dont want to accept it!

How can I see what really get the pixelcoord? Because if I print out the string it is there!

Share this post

Link to post
Share on other sites

I did also like set direct to function the string:

$buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, 0xFF455E, False, True, $image_path, $text)


$buttonActivated1 = ifButtonActivated("[CLASS:TFormResearchGR]", $btn_meta_class, $btn_meta_instance, Int(0xFF455E), False, True, $image_path, $text)

I find it very weird :(

Share this post

Link to post
Share on other sites

O now I found somewhere i overwritten then :(

from function metacolor:16733290
from function metacolor:16733290
local metacolor:16729438
local metacolor with int:16729438


Share this post

Link to post
Share on other sites

if I set it as Global then it works perfect, but hen I dont pass it to function.

But I can't let go how can it be that passing it to function gives different results, this is not possible!

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

  • Similar Content

    • Borges
      By Borges
      Sorry if I posted in wrong section but...
      how can I do something like that?
      If PixelSearch(660, 30, 670, 38, 0x242424, 0 , 1) <> @error Then
       ElseIf PixelSearch(800, 30, 810, 38, 0x242424, 0 , 1) <> @error Then
    • squidol
      By squidol
      I need help about pixel search. The problem with the script below is that PixelSearch does not continue on the coordinates where it has stopped.
      When the first pixelsearch finds the 1st pixel, it should move the mouse over it and new pixels would appear just like hovering over menus. Then upon hover, there would be another PixelSearch to see if the second red pixel is found. If not found, then it should resume the first PixelSearch instead of starting from left to right again. 
      For example we are doing a pixelsearch on two straight lines with coordinates  [x,y]  :
      [0,0] [1,0] [2,0]
      [1,0] [1,1] [1,2]
      Pixelsearch finds the coordinate [1,0] matching our color. So it checks the pixel just below it which is [1,1] to see if it is color red. If not red then it should continue searching starting on coordinates [2,0] instead of going back to [0,0]
      Local $bflag = False Do     ToolTip("finding..",0,0,"")     Sleep(500)     $var = PixelSearch(591, 169, 1365, 740, 0x464950,50) ; look for initial pixel     If Not @error Then ;         MouseMove($var[0],$var[1],0) ;move on the button to show new selections, new pixels         sleep(1000)         ;search for the red pixel on an area above the first pixel coords which was          ;generated when mouse cursor was hovered on the first pixel found.         $redpixel = PixelSearch($var[0]-50,$var[1]-50,$var[0]+50,$var[1]+50,0xFF0048)          If Not @error Then ; Found the 2nd pixel                 ToolTip("found...",0,0,"")             $bflag = True          EndIf     EndIf Until $bflag I can pay 50USD through Paypal for a working solution. thanks   
    • MrMajorThorburn
      By MrMajorThorburn
      Using sample code:
      #include <MsgBoxConstants.au3> ; Find a pure red pixel in the range 0,0-20,300
      Local $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000)
      If Not @error Then
          MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1])
          MsgBox($MB_SYSTEMMODAL, "", "Pure Not Found")
      EndIf ; Find a pure red pixel or a red pixel within 10 shades variations of pure red
      $aCoord = PixelSearch(0, 0, 20, 300, 0xFF0000, 10)
      If Not @error Then
          MsgBox($MB_SYSTEMMODAL, "", "X and Y are: " & $aCoord[0] & "," & $aCoord[1])
          MsgBox($MB_SYSTEMMODAL, "", "Variant Not Found")
      EndIf   and the attached screenshot which has Pure Red (FF0000) in one icon in the area being searched. Would someone please check this out for me?
    • Cyberjunk
      By Cyberjunk
      Hello, I am new to both Programming and this forum. I have done a few tiny projects that were successful and fell in love with Autoit. So now I am trying to learn new things as I go. I have read the Help docs on my following question, I have gone thru all of that. and I am sure as soon as you see my code you will be saying OMG why did he do that, or OMG how can you forget to add this.. But when your new you take the path of least resistance to get the outcome you want.

      I am trying to make a code that will open a piece of software, then open a browser (which has a handful of tabs already open) go to a web page (one of the tabs) and search an area of the web page for a specific color, if that color is found I want it to close the browser and go back and start again. If that color is not found on that page I want it to switch tabs and search that page for the color. If the color is found on that page I want it to close the browser and start again. If the color is not found on either page, I want it to open another browser and go to website and do some things I will add once i get past this obstacle.

      I already have it almost there my code will open my software, open the browser, do the searches, find or not find the color, the part I am having trouble with is the if and else and what happens if and what it does if it does not. So the first code I have does everything I want except if it finds the color on the first run it closes the browser, but then when it starts the process again it doesnt check for the color. its like it skips the scanning part and goes straight to the opening of the second browser and finishes the code.
      Run( "C:\Programs\myprogram.exe", "", @SW_SHOWDEFAULT ) Sleep(4000) MouseClick("left", 613,272) ;click in program Sleep(500) Example() Func Example() MouseClick("left", 632,456) ;click in program Sleep(500) MouseClick("left", 527,456) ;click in program Sleep(15000) Run( "C:\Programs\browser1.exe", "", @SW_SHOWMAXIMIZED ) Sleep(Random(4000,6000)) EndFunc ;==>Example MouseClick("left", 162,14) ;switch tab Sleep(Random(5000,8000)) MouseClick("left", 354,14) ;switch tab Sleep(Random(5000,8000)) $aCoord = PixelSearch(873, 485, 900, 600, 0xDD0000, 10) ;search for color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else MouseClick("left", 162,14) ;switch tab Sleep(1000) EndIf MouseClick("left", 162,14) ;click tab again just to be sure its loaded Sleep(4000) $aCoord = PixelSearch(1052, 308, 1120, 431, 0xFF0000, 10) ;search for this color If Not @error Then MouseClick("left", 1338,6) ;close browser1 Sleep(1000) Call("Example") Else Run( "C:\Programs\browser2.exe", "", @SW_SHOWMAXIMIZED ) Sleep(2000) EndIf MouseClick("left", 134,45) ;click on address bar Sleep(1000) Send("aspecificwebpage.com") ;input website Send("{enter}") ;hit enter Sleep(15000) MouseClick("left", 1338,6) ;close browser2 Sleep(500) MouseClick("left", 1338,6) ;close browser1 Sleep(500) MouseClick("left", 625,454) ;click in program Sleep(500) MouseClick("left", 634,271) ;click in program Sleep(500) MouseClick("left", 917,245) ;close program Sleep(500) SO it makes the first scan and is successful, if the color is found it closes as I want, but then when nit starts the code again it does not scan anything the second time.

      and on the other side, if the color is not found naturally everything works as it is written.
      I want to guess by all the weird colors in the code sniplet I have a massive amount of errors. It is like a rainbow of text up there. different from what i see in AutoIT

      Any help would be appreciated.

    • Nitrolord
      By Nitrolord
      I had this problem with PixelGetColor not giving me the same HEX Color as the AU3Info Tool and searched every were with no luck then had a OH DA moment LoL.
      The problem is that the
      "PixelGetColor ($mouseX[0], $mouseY[1])"
      is looking rite at the very tip of the mouse pointer not under it.  So you have to set a -3 after the [0] and [1].  
      "PixelGetColor ($mouseX[0] -3, $mouseY[1] -3)"
      to make it search next to the pointer not on the pointer.  You may have to adjust this a bit for your display but you should not have  to go more then -5.  -3 seems to work best for me.
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 141, 127, 276, 231) $Input1 = GUICtrlCreateInput("", 8, 8, 121, 21) $Label1 = GUICtrlCreateLabel("Press or Hold F1 to get Hex color at Mouse X -3, Y-3 Pos,", 8, 40, 124, 73) GUISetState(@SW_SHOW) HotKeySet("{f1}","MousePos") Func MousePos() $aPos = MouseGetPos() $PGC = PixelGetColor($aPos[0] -3, $aPos[1] -3) GUICtrlSetData($Input1, "0x" & Hex($PGC, 6)) EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd