Method

In AskiaScript, a method of an object is an action or function that is executed within the object's context. The action could:

In most common programming languages, a method may or may not be able return a value (procedure vs function). In AskiaScript, all methods return a value. To invoke a method, it is required to use parenthesis "()" after the name of the method.

my_variable.method()

The pair of parenthesis can contain arguments and optional arguments.


Syntax without arguments

my_variable.method()

e.g.
myArray.Sort()

With one argument

my_variable.method(argument)

e.g.
myDate.ToString("yyyy-MM-dd")

With multiple arguments

All arguments will be separated with the comma character (,) and should be in the right order.

my_variable.method(arg1, arg2, arg3)

e.g.

myString.Replace("Hello", "Hi")

With multiple and optional arguments

When an argument is optional, you have to indicate both the name of the argument and its value, using the character: colon (:). In this case, the order of the arguments does not matter, and all unspecified arguments will be internally set with a default value.

my_variable.method(arg3 : value3, arg2 : value2)

e.g.
q1.Iteration(SubLoop : 2, ParentLoop : 3)

Loop of loop ("ParentLoop" and "SubLoop") with the question "q1". Here, we want to obtain the state of the question "q1" in the third iteration of "ParentLoop" and the second iteration of "SubLoop". If one of the arguments is omitted, it takes the value of the current iteration of the loop:

q1.Iteration(SubLoop : 2)

(Second iteration of "SubLoop" and the current iteration of "ParentLoop")

Note: When the script is outside the loop all arguments are required. See: Question.Iteration method

Create your own Knowledge Base