Reputation: 37
When making a small project i added a GUI and it suddenly requires return? i want to have it ask what a folder should be named then create it it was working, but then i added GUI for what you want to download and it requires return I couldn't find anything else on this topic anywhere else
Working code:
if !FileExist(%UserInput%) {
MsgBox, 0, Serkket Servers, Server will build files, press ok to continue `n Server will open when done
FileCreateDir, %UserInput%
}
Not Working code:
if !FileExist(%UserInput%) {
Gui, New,, Server Software
Gui, Color, 707070
Gui, Add, DropDownList, vServVers, 1.16.5|1.16.4|1.16.3|1.16.2|1.16.1|1.15.2|1.15.1|1.15|1.14.4|1.14.3|1.14.2|1.14.1|1.14|1.13.2|1.13.1|1.13|1.12.2|1.12.1|1.12|1.11.2|1.11.1|1.11|1.10.2|1.9.4|1.9.2|1.9|1.8.8|1.8.3|1.8
Gui, Add, Button, Default w80, OK
Gui, +Resize +MinSize480x240
Gui, Show
Pause, On
ButtonOK:
Gui, Submit
MsgBox, 0, Serkket Servers, Server will build files, press ok to continue `n Server will open when done
FileCreateDir, %UserInput%
}
Upvotes: 0
Views: 153
Reputation: 26246
The return in this case is required because you have a ButtonOK:
label that hasn't been properly closed off to form it's subroutine. As this return
is needed, you will need to move the label elsewhere in your code, somewhere outside the current section. If this code is happening at the top of your file, you will need to move it outside the autorun segment.
To aid with this, we can give the GUI a label which is done using Gui, MyLabel:New
. This allows AHK to work with different GUIs at the same time, but it also makes it easier to deal with the default window event handlers by changing GuiClose
to MyLabelGuiClose
.
This updates your conditional statement to:
if !FileExist(%UserInput%) {
Gui, SelectServers:New, +Resize +MinSize480x240 +HwndSelectServersHwnd, Server Software
Gui, SelectServers:Color, 707070
Gui, SelectServers:Add, DropDownList, vServVers, 1.16.5|1.16.4|1.16.3|1.16.2|1.16.1|1.15.2|1.15.1|1.15|1.14.4|1.14.3|1.14.2|1.14.1|1.14|1.13.2|1.13.1|1.13|1.12.2|1.12.1|1.12|1.11.2|1.11.1|1.11|1.10.2|1.9.4|1.9.2|1.9|1.8.8|1.8.3|1.8
Gui, SelectServers:Add, Button, Default w80 gSelectServersButtonOK, OK ; <- don't forget to connect the handler
Gui, SelectServers:Show
WinWaitClose, ahk_id %SelectServersHwnd% ; <- This is a better choice than "Pause, On"
}
and this can be added anywhere outside of the autorun section (like at the bottom of the file)
return ; <- makes sure the auto run section has ended (only needed once)
SelectServersButtonOK:
Gui, SelectServers:Submit
MsgBox, 0, Serkket Servers, Server will build files, press ok to continue `n Server will open when done
FileCreateDir, %UserInput%
Gui, SelectServers:Destroy
return
SelectServersGuiClose:
SelectServersGuiEscape:
; TODO: Handle cancelling selection GUI
; e.g. ExitApp, cancel folder creation, etc.
Gui, SelectServers:Destroy
return
Upvotes: 1