Else with no matching If error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
j3kser
Posts: 5
Joined: 28 Jul 2021, 19:23

Else with no matching If error

28 Jul 2021, 19:33

Hello everyone i am pretty new to this forum and now i need help i have a code that is having the error "Else with no If " either i am just stupid or there is something wrong maybe someone can help heres the code:

Code: Select all

^.::
Gui, Destroy 
Gui, Font, s11
Gui, add, text, section, Type in a valid Katheryne Gacha banner (All banner are case sensitive)
Gui, Font, s9
Gui, Add, Edit, vEdit1
Gui, Add, Button, Default gRunBtn, Run 
Gui, add, Button, Default gRunBtn2, Help
Gui, Show,w260 h150,Auto Roll
Return

RunBtn: 
Ready = 1
Gui, Submit, nohide 
Gui, Destroy
if Edit1 in Albedo, Ayaka, Beginner, Eula, Ganyu, Hu Tao, Kazuha, Keqing, Klee, Klee 2, Standard, Tartaglia, Tartaglia 2, Venti, Venti 2, Weapons, Xiao, Zhongli, Zhongli 2
\::
if Ready > 0
{
loop

Banner = %Edit1%
Command = *wish %Banner% {enter}

	loop, 5{
	Send, %Command%
	sleep, 12000
	}

Sleep, 300000
}
Else
{
MsgBox, 0, Auto Roll, You Havent Chosen a Banner pls press crtl + . to chose a banner
}



Return


Else
{
MsgBox,0,Auto Roll, Invalid Banner. please choose one of the banner in the help section
Gui, Destroy 
Gui, Font, s11
Gui, add, text, section, Type in a valid Katheryne Gacha banner (All banner are case sensitive)
Gui, Font, s9
Gui, Add, Edit, vEdit1
Gui, Add, Button, Default gRunBtn, Run 
Gui, add, Button, Default gRunBtn2, Help
Gui, Show,w260 h150,Auto Roll
}
Return



MsgBox, You have chosen %Edit1% press \ to start the script Auto Farming(make sure u are tab in to discord)
Return

RunBtn2:
MsgBox, 0, Auto roll, The following are all currently active banner in Katheryne discord bot`n `nAlbedo, Ayaka, Beginner, Eula, Ganyu, Hu Tao, Kazuha, Keqing, Klee, Klee 2, Standard, Tartaglia, Tartaglia 2, Venti, Venti 2, Weapons, Xiao, Zhongli, Zhongli 2
Return





Esc::
Ready=0
MsgBox, 0, Auto Roll, You have exited the script
ExitApp

return
thank you in advance
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Else with no matching If error

28 Jul 2021, 19:49

The error message shows you the line number of the problem.
Every use of an Else must belong to (be associated with) an If statement above it.
In your script, Else is preceded by Return rather than If. If that Return is meant to be part of a block, then it would need to be placed inside the block (braces).
User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Else with no matching If error

28 Jul 2021, 19:57

A couple other observations...

This line:

Code: Select all

if Edit1 in Albedo, Ayaka, Beginner, Eula, Ganyu, Hu Tao, Kazuha, Keqing, Klee, Klee 2, Standard, Tartaglia, Tartaglia 2, Venti, Venti 2, Weapons, Xiao, Zhongli, Zhongli 2
...should not have spaces after the commas. See the documentation on if...in.

You are apparently trying to make the hotkey definition below subject to the "if" statement that precedes it. It doesn't work that way. It wouldn't be inline with other code like than in any event. Hotkey subroutines are launched by the event of the hotkey press, not executed by the flow of the code. To make hotkeys conditional, see the #If directive.

Code: Select all

\::
if Ready > 0
{
loop

Banner = %Edit1%
Command = *wish %Banner% {enter}

	loop, 5{
	Send, %Command%
	sleep, 12000
	}

Sleep, 300000
}
Else
{
MsgBox, 0, Auto Roll, You Havent Chosen a Banner pls press crtl + . to chose a banner
}



Return
j3kser
Posts: 5
Joined: 28 Jul 2021, 19:23

Re: Else with no matching If error

28 Jul 2021, 20:18

Thx for the help everyone i have the solution i can just separate the code it, and it works just like i want it i am still new to ahk and need to learn more and again thx for the help
j3kser
Posts: 5
Joined: 28 Jul 2021, 19:23

Re: Else with no matching If error

28 Jul 2021, 20:20

Also can i ask one more thing it seems the when i run the "part 2" of the code which is after the \ it created a new instance. why does this happened?
User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Else with no matching If error

28 Jul 2021, 20:28

Are you asking why it creates two instances of AHK scripts when you've separated them into two separate scripts and run both of them?
j3kser
Posts: 5
Joined: 28 Jul 2021, 19:23

Re: Else with no matching If error

28 Jul 2021, 20:31

no, i think what i mean is when i press the \ it just create the new instance pop up window for a weird reason it's like when you run a newer instance when an older one is running
j3kser
Posts: 5
Joined: 28 Jul 2021, 19:23

Re: Else with no matching If error

28 Jul 2021, 20:59

so i did something and it fix the new instance problem so this is solved thx for the helped

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Nerafius, RandomBoy and 112 guests