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
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
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
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
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