Variable from PixelGetColor not being recognised in simple if-else loop Topic is solved

Ask gaming related questions (AHK v1.1 and older)
The_Rizzler
Posts: 2
Joined: 16 Oct 2021, 05:00

Variable from PixelGetColor not being recognised in simple if-else loop

Post by The_Rizzler » 16 Oct 2021, 05:10

Hi everyone,
I'm a new user who's writing a script for exp farming in an RPG that should operate differently depending on whether the player is in the overworld or in a battle, and I'm trying to achieve this by checking for the colour of a specific pixel. However, the code under "else" is always run, even when the conditions of the if statement should be met. The script I'm using is as follows:

Code: Select all

fightcolor := 0x000280
resultcolor := 0x002091

^g::
  Loop
  {
    PixelGetColor, color, 18, 464, RGB
    if %color% = %fightcolor% or %color% = %resultcolor%
    {
      SendEvent, {k down}
      Sleep 10
      SendEvent, {k up}
      Sleep 10
    }
    else
    {
      SendEvent, {s down}
      Sleep 10
      SendEvent, {s up}
      Sleep 10
    }
  }
Return
^h::Pause
^j::
  PixelGetColor, color, 18, 464, RGB
  MsgBox %color%
  
I've revised and tweaked this code numerous times, but it's always the same result. I've also tried activating it during both states. When I press control ctrl+J to show the color, it always comes up with the same result I'm using in the variables, as expected. But whenever the script is running, it always spams the S key whether in the overworld or battle, and I can't figure out why.

Any help would be greatly appreciated. Thank you!

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Variable from PixelGetColor not being recognised in simple if-else loop  Topic is solved

Post by mikeyww » 16 Oct 2021, 07:02

Code: Select all

color = 1
fightcolor = 1
resultcolor = 1
if %color% = %fightcolor% or %color% = %resultcolor%
 MsgBox A
If (color = fightcolor OR color = resultcolor)
 MsgBox B
If color in %fightcolor%,%resultcolor%
 MsgBox C
Explained:

https://www.autohotkey.com/docs/commands/IfExpression.htm

https://www.autohotkey.com/docs/Variables.htm#Expressions

https://www.autohotkey.com/docs/commands/IfIn.htm

The_Rizzler
Posts: 2
Joined: 16 Oct 2021, 05:00

Re: Variable from PixelGetColor not being recognised in simple if-else loop

Post by The_Rizzler » 16 Oct 2021, 08:11

Thanks a bunch, this was a great help. I know it's simple, but it still means a lot to someone like me who has little experience with scripting languages.

Post Reply

Return to “Gaming Help (v1)”