vendredi 25 octobre 2019

AutoHotKey - repeating if statement keeps treating its condition as true in a loop

I'm trying to create an autoclicker using AutoHotKey for a game which has a system for fishing. This system makes an icon of a black exclamation mark surrounded by a large square border of white appear above your head, at which point you have to spam left click to catch the fish. Since the time at which the icon appears is randomly different each time, I have to be able to determine the time at which to spam click dynamically.

I've attempted to do that using PixelGetColor(as shown below) to find a particular pixel which ends up white whenever the exclamation mark appears, yet it never detects the exclamation mark, and more concerningly, whenever it detects the particular pixel on my screen to be white, the if statement's condition following PixelGetColor always returns true.

Toggle = False

loop 
{
  if (Toggle = "true")
  { 
    Sleep, 100
    PixelGetColor, color, 966, 463
    if (color = 0xFFFFFFFF) {
          MsgBox, It works!
    }
  }
}

F1::
if (Toggle = "true") {
  Toggle = False
}
else {
  Toggle = True
}

F1 is bound to a boolean which determines if the code inside of the loop is ran or not. The last two inputs for PixelGetColor, 966 and 463, are the x and y positions of the specific pixel respectively.

I'm expecting to get different values for the color once I start moving my camera in game, but after it detects white it proceeds to spam the message about the script 'working' when it clearly doesn't.

Simply put, what the hell is going on? I've been trying to figure that out for a while now. If anyone could give an explanation of what I've done wrong, as well as a snippet of code for what should be done inside of the loop to make the program work as intended, I would be eternally(well, almost) grateful.

Aucun commentaire:

Enregistrer un commentaire