Function inside if statement Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
guirc
Posts: 2
Joined: 20 Jun 2021, 15:40

Function inside if statement

Post by guirc » 20 Jun 2021, 15:55

Code: Select all

Queuedcheck()
{
    PixelGetColor, queue_color, 1140, 57, RGB
    if (queue_color = 0x005176) {
        return 0
	} else  { 
        return 1
	}
}

if !Queuedcheck()
	Gosub, start_Queue
This does not work properly

Code: Select all

Queuedcheck()
{
    PixelGetColor, queue_color, 1140, 57, RGB
    if (queue_color = 0x005176) {
        return 0
	} else  { 
        return 1
	}
}

variable = Queuedcheck()
if !variable
	Gosub, start_Queue
This does work properly
Coming from some C projects I wonder: why do I need this variable? If more context is needed I will happily provide it

gregster
Posts: 8990
Joined: 30 Sep 2013, 06:48

Re: Function inside if statement  Topic is solved

Post by gregster » 20 Jun 2021, 16:09

If variable = Queuedcheck() works for you, then for the wrong reasons. Check for yourself:

Code: Select all

variable = Queuedcheck()
msgbox % variable
It assigns a literal string, and doesn't actually call the function, and a non-blank string is considered true.
variable := Queuedcheck() (with := instead of = ) would call the function and assign the result to the variable.

But if !Queuedcheck() should be fine.

The problem must be elsewhere - how about Coordmode ? Are you using screen coordinates or the default active window coords? If the latter, is the right window active when you check?

guirc
Posts: 2
Joined: 20 Jun 2021, 15:40

Re: Function inside if statement

Post by guirc » 20 Jun 2021, 17:03

gregster wrote:
20 Jun 2021, 16:09
It assigns a literal string, and doesn't actually call the function, and a non-blank string is considered true.
I now see why it wrongly worked.
Anyway, turns out it I miss implemented the function by calling it too early - before the pixel changed to its desired color - and causing the program to go back to start_Queue. if !Queuedcheck() DOES work just fine. :dance:
Thank you for your help.

Post Reply

Return to “Ask for Help (v1)”