P
ProgramGamer
Guest
Hi!
In my current project, I have quite a few functions where the last argument is an optional instance id. They are generally of the following form:
The problem with this is that arguments are not all listed in the function declaration, which imo hinders readability a bit. Since, according to the manual, unset arguments simply get initialized to undefined, I thought I would check for this in the function body, which leads to this mildly more readable form:
Which, granted, does work when I run the game. However, the code editor still gives me warnings when I call this function, telling me that I'm passing fewer arguments than are necessary. I tried following the JSDoc format for optional arguments, but this doesn't seem to remove the warnings:
Is there a way to remove these unwanted warnings, or must I use the (imho) less legible argument_count strategy for the time being?
Thanks in advance!
In my current project, I have quite a few functions where the last argument is an optional instance id. They are generally of the following form:
GML:
function fn(arg_1)
{
var arg_2 = argument_count > 1 ? argument[1] : self;
arg_2.something = arg_1; // or something to this effect
}
GML:
function fn(arg_1, arg_2)
{
if (is_undefined(arg_2)) arg_2 = self;
arg_2.something = arg_1; // or something to this effect
}
GML:
/// @function fn(arg_1, arg_2)
/// @param arg_1 The first, non-optional argument
/// @param [arg_2] The second, optional argument
function fn(arg_1, arg_2)
{
if (is_undefined(arg_2)) arg_2 = self;
arg_2.something = arg_1; // or something to this effect
}
Thanks in advance!