Functions

In Robin, automations can be split in functions. That way, sections that are repeated can be developed once, but they are set to run multiple times. A function is marked with the “function” term followed by the function name.

In the below example function “today” contains the “Get Current Date and Time” action.

function today
    DateTime.Current DateTimeFormat:DateTimeFormat.DateAndTime Offset:'0' CurrentDateTime=> CurrentDateTime
end
A function can then be called using the term “call” followed by the function name.

call today

Passing Variables

All the variables that are used in a function are not related to the variables included in other functions or the automation in general.

To pass a variable to the function as input, it needs to be set in the “call” statement.

For example, the function addition, requires two values. The values num1 and num2 which are passed through the call statement. To pass a value in the function, use the name of the variable used in the function, colon and then the value passed to the function variable, or the variable holding that value.

call addition num1:10 num2:5
Here, the variables passed are num1 and num2. The values assigned are 10 and 5 respectively.

If the values are passed through a variable which is used previously in the automation, it should appear as follows:

set value1 to 10
set value2 to 5

function addition num1, num2
    set total to num1 + num2
end
call addition num1:value1 num2:value2
Similarly, as in the above example, value1 and value2 are two variables which are not used in the automation at all, the value total is used within the function, but it cannot be used in the automation in general. The output value calculated within the function, needs to be exported as a function output. This is a prerequisite to be able to utilise the result in the general automation, or on another function.

To set the output variables, use the name of the variable in the function, arrow (=>) and then the variable used in the automation. Apart from there, all the output variables need to be stated in the function definition line as well.

set value1 to 10
set value2 to 5

function addition num1, num2, output total, output difference
    set total to num1 + num2
    set difference to num1 - num2
end
call addition num1:value1 num2:value2 total=>output1 difference=>output2

Global Variables

Alternatively, using the “g:” prior to a variable in a function, marks the variable as global. That way the variable is not required to be set as output.

The above example would look like this.

set value1 to 10
set value2 to 5

function addition num1, num2
    set g:total to num1 + num2
end
call addition num1:value1 num2:value2