Getarg

From Hercules Wiki
Revision as of 09:38, 9 June 2013 by Via (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Syntax

  • getarg(<index>[, <default value>]);
  • getarg(<index>[, <"default value">]);

Description

This function retrieves a parameter inside a function, which was passed into an invoking callsub or callfunc call. The parameters are referred to by an zero-based index, which means, the first parameter has index 0, the second parameter 1, and so on. Optionally a default value can be specified, which will be used, when no parameter was passed with given index (optional parameter functionality for script functions).

If there is no such parameter at given index and no default value exists, or if the invoking script is not a function, the script terminates with an error.

The parameter default value is available since r10773.

Examples

    callsub L_dosomething, "toast";
    end;
L_dosomething:
    mes "*does something with a "+getarg(0, "not recognized thing")+"*";
    close2;
    return;

This results in message *does something with a toast*. If "toast" were not passed as parameter, the message would be *does something with a not recognized thing*.