Struggling to work with multiple flags/conditions

Get help with using AutoHotkey and its commands and hotkeys
ast
Posts: 7
Joined: 09 Nov 2019, 23:11

Struggling to work with multiple flags/conditions

09 Nov 2019, 23:18

I'm really struggling to get this to work, I'm rather new to ahk and I've tried googling for similar issues but have been unable to make it work still :( The issue currently is that the script would SendB instead of SendA even though one := true and I've doubled checked to make sure that it is actually true, before i was running into issues where it would sendA and sendB both at the same time which is not something i want it to do either. Any help would be greatly appreciated!

Code: Select all

$2::
PixelSearch, FoundX, FoundY, 1307, 966, 1307, 966, 0x3454A2, 0, Fast RGB
if ErrorLevel = 0
{
    one := true
}
else if ErrorLevel = 1
PixelSearch, FoundX, FoundY, 650, 527, 650, 527, 0x90DAFD, 0, Fast RGB
if ErrorLevel = 0
{
    two := true
}

#If (one := false)
Gosub, SendB

#If (two := false)
Gosub, SendA

#If (two) and (one)
Send, {;}


Return

SendA: 
PixelSearch, FoundX, FoundY, 1217, 966, 1217, 966, 0x6BA6B5, 0, Fast RGB
If ErrorLevel = 0
{
Send, {[ }
}
else if ErrorLevel = 1
	{
PixelSearch, FoundX, FoundY, 1261, 966, 1261, 966, 0x17252D, 0, Fast RGB
If ErrorLevel = 0

{
Send, {]}
}

SendB: 
PixelSearch, FoundX, FoundY, 1349, 966, 1349, 966, 0x343A3C, 0, Fast RGB
If ErrorLevel = 0
{
Send, {'}
}
else if ErrorLevel = 1
	{
PixelSearch, FoundX, FoundY, 1217, 966, 1217, 966, 0x6BA6B5, 0, Fast RGB
If ErrorLevel = 0
{
Send, {[}
}
else if ErrorLevel = 1
	{
PixelSearch, FoundX, FoundY, 1261, 966, 1261, 966, 0x17252D, 0, Fast RGB
If ErrorLevel = 0

{
Send, {]}
}

Hellbent
Posts: 740
Joined: 23 Sep 2017, 13:34

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 02:36

I only took a quick look and found 2 issues (there could be more).

1:

You don't use #If like that.

Just use if


2:

Code: Select all

If (two := false)
That is not checking if it's false it's setting it to false.

use if(two = false)
ast
Posts: 7
Joined: 09 Nov 2019, 23:11

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 20:23

Thanks alot for the help I've made the changes however now it does both sendA and sendB at the same time, how do I make it so its either sendA or sendB but not both

Code: Select all

$2::
PixelSearch, FoundX, FoundY, 1307, 966, 1307, 966, 0x3454A2, 0, Fast RGB
if ErrorLevel = 0
    one := true
else 
    one := false
PixelSearch, FoundX, FoundY, 650, 527, 650, 527, 0x90DAFD, 0, Fast RGB
if ErrorLevel = 0
    two := true
else
two := false

If(one = false)
Gosub, SendB

If(two = false) 
Gosub, SendA

If (two) and (one)
Send, {;}

I've tried

Code: Select all

If(one = false) and (two = true)
but it didn't work, any help would be greatly appreciated :)
Hellbent
Posts: 740
Joined: 23 Sep 2017, 13:34

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 20:31

ast wrote:
10 Nov 2019, 20:23
how do I make it so its either sendA or sendB but not both

Code: Select all

If(one = false)
	Gosub, SendB
else If(two = false) 
	Gosub, SendA
Give that a try.
ast
Posts: 7
Joined: 09 Nov 2019, 23:11

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 20:51

Hellbent wrote:
10 Nov 2019, 20:31
ast wrote:
10 Nov 2019, 20:23
how do I make it so its either sendA or sendB but not both

Code: Select all

If(one = false)
	Gosub, SendB
else If(two = false) 
	Gosub, SendA
Give that a try.
It's still doing both sendA and sendB at the same time . It's really weird because the very first pixelsearch should be found, I've tested it by making a script with just the first pixelsearch and it works so the values are right did I somehow mess up somewhere for the first pixelsearch here, because its behaving as though the very first pixel can't be found.
Last edited by ast on 10 Nov 2019, 21:01, edited 2 times in total.
Hellbent
Posts: 740
Joined: 23 Sep 2017, 13:34

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 20:57

ast wrote:
10 Nov 2019, 20:51
It's still doing both sendA and sendB at the same time
Then you have something else going on in your script. There is no way that it would be doing both if you put it in right.
ast
Posts: 7
Joined: 09 Nov 2019, 23:11

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 20:59

Sorry I've updated my previous comments with more info
Hellbent
Posts: 740
Joined: 23 Sep 2017, 13:34

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 21:05

ast wrote:
10 Nov 2019, 20:59
Sorry I've updated my previous comments with more info
Regardless of your edit, regardless of the first or second search finding something, there is no way that it would be doing both unless there is something else going on in your script.
User avatar
Xtra
Posts: 1476
Joined: 02 Oct 2015, 12:15

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 21:08

You need a Return for each of your gosub routines otherwise SendA: label does not stop when its completed it falls through and runs SendB:
Fix that first and then any other issues can be addressed. (if needed)
ast
Posts: 7
Joined: 09 Nov 2019, 23:11

Re: Struggling to work with multiple flags/conditions

10 Nov 2019, 21:26

Xtra wrote:
10 Nov 2019, 21:08
You need a Return for each of your gosub routines otherwise SendA: label does not stop when its completed it falls through and runs SendB:
Fix that first and then any other issues can be addressed. (if needed)
After adding the return and changing the script slightly it works perfectly. Thanks alot Hellbent and Xtra :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot], just me, MrGrayline, pythonker, QuestVBA, ulraf and 195 guests