-1

i run a program that is looking for pixel. but if the pixel is not in range from Search1, then it should search in search2 range. But it ignore my else if. if my pixel is not in Search1 then my program do nothing and wait until it is in range again from Search1.

What did i have made wrong? i thought it is right to place Else if on this way :/

void SEARCHING()
{
    while (true)
    {
        if (GetKeyState(Keys.X) == 1)
        {
            try
            {
                object search1 = au3.PixelSearch(768, 432, 1200, 675, 0xDD2C02, 5);
                object search2 = au3.PixelSearch(600, 337, 1319, 864, 0xDD2C02, 5);
                object search3 = au3.PixelSearch(400, 225, 1519, 900, 0xDD2C02, 5);
                object search4 = au3.PixelSearch(200, 70, 1519, 900, 0xDD2C02, 5);


                if (search1.ToString() != "1")
                {
                    object[] search1Coord = (object[])search1;
                    au3.MouseClick("LEFT", (int)search1Coord[0] + 50, (int)search1Coord[1] , 1, 1);
                }
                
                else if (search2.ToString() != "1")
                {
                    object[] search2Coord = (object[])search2;
                    au3.MouseClick("LEFT", (int)search2Coord[0] + 50, (int)search2Coord[1] , 1, 1);

                }
                else if (search3.ToString() != "1")
                {
                    object[] search3Coord = (object[])search3;
                    au3.MouseClick("LEFT", (int)search3Coord[0] + 50, (int)search3Coord[1] , 1, 1);
                }

                else if (search4.ToString() != "1")
                {
                    object[] search4Coord = (object[])search4;
                    au3.MouseClick("LEFT", (int)search4Coord[0] + 50, (int)search4Coord[1] , 1, 1);
                }                                                                    
            }
            catch { }                
        }        
    }
}
ShiiikK
  • 13
  • 6
  • 6
    Have you debugged it to see exactly what `au3.PixelSearch()` returns? – 001 Mar 17 '22 at 13:56
  • 2
    Now is a good time to step through the code [with a debugger](https://stackoverflow.com/q/25385173/328193) to more specifically observe its behavior. It's not "ignoring" any code, it's executing the code line by line. It's *also* **completely ignoring all exceptions**, which is a famously bad idea. When you step through in a debugger, what specifically happens. Which operation produces an unexpected result? What values were used at the time? What was the result? What result was expected? Why? – David Mar 17 '22 at 13:58

2 Answers2

1

If the search1 fails, you will get error. Because of try/catch, you will jump immediatelly to catch. You need to use try/catch on each search.

Jenda
  • 26
  • 2
0

If you are using AutoItx, it look's like there is a bugg in the PixelSearch methods. Take a look a this answer, it migth help you

PixelSearch in certain area of monitor

ymt
  • 29
  • 2