Function with parameter defaulting to an object

Get help with using AutoHotkey and its commands and hotkeys
expert_vision
Posts: 21
Joined: 13 Jan 2014, 10:47

Function with parameter defaulting to an object

19 Oct 2014, 07:14

Why can't I do this?

Code: Select all

testFunc(parameter := new Object())
{
	return 123
}
It says : "Unsupported parameter default."
Why not?
User avatar
trismarck
Posts: 506
Joined: 30 Sep 2013, 01:48
Location: Poland

Re: Function with parameter defaulting to an object

19 Oct 2014, 07:35

Related quote from the documentation:
Optional Parameters ([url=http://ahkscript.org/docs/Functions.htm#optional]link[/url]) wrote:A parameter's default value must be one of the following: true, false, a literal integer, a literal floating point number, or a quoted/literal string such as "fox" or "" (but strings in versions prior to 1.0.46.13+ support only "").
Coco
Posts: 771
Joined: 29 Sep 2013, 20:37
GitHub: cocobelgica

Re: Function with parameter defaulting to an object

19 Oct 2014, 08:02

You can specify a really unique(e.g.: unique set of characters) default value and if parameter remains as such then assign it an object or you can use variadic parameter:

Code: Select all

testFunc(parameters*)
{
    parameter := parameters.MaxIndex() ? parameters[1] : parameters
    MsgBox % IsObject(parameter)
}

testFunc()
return

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, mitsakos156, ndr, teadrinker, vsub and 129 guests