Is empty return still required in V2? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Is empty return still required in V2?

Post by Coiler » 06 Dec 2020, 11:20

I noticed in the docs for V2, the page for "return" does not have a return at the end of the hotkey in the example at the bottom of the page. Here's the hot-key code for convenience:

Code: Select all

#z::  ; Win-Z
^#z::  ; Ctrl-Win-Z
{
    MsgBox "A Win-Z hotkey was pressed."
    if GetKeyState("Ctrl")
        return  ; Finish early, skipping the function call below.
    MyFunction()
}
I was wondering if this means that return is no longer required at the end of hotkeys and functions as long as they use scope brackets { }?

I've always had trouble remembering to add empty returns to everything, coming from a C++ background where its not required. I'm also a coder that absolutely has to add comments above every line of code explaining what's happening, and there is absolutely nothing meaningful to comment about an empty return 8-)

Example of one of my functions:

Code: Select all


Hotex(com)
{
	; clear tic states after every command (do this BEFORE sending the hot-key, in case the key some how triggers more changes)
	LinkTic := TicNONE

	; send command & return
	Send( com )

	; TODO: DISPLAY NAME OF COMMAND

	; done
	return
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Is empty return still required in V2?  Topic is solved

Post by swagfag » 07 Dec 2020, 03:06

its not required. v2 hotkeys are now entirely based on functions instead of labels. a function whose scope ends implicitly returns an empty string. single line hotkeys implicitly return(same as in v1)

Post Reply

Return to “Ask for Help (v2)”