To access data, you need to use the data-binding mechanism. Suppose you want to calculate the sum of two text fields. You need to:
- Create two text fields and a label to show the sum.
- Select the first text field and set the data binding to "valueA"
- Select the second text field and set the data binding to "valueB"
- Select the label and set the data binding to "sum"
- Add a script widget to the canvas (use the cloud button in the topbar)
- Add a button and wire it to the script. When the user clicks on the button the script is executed.
Your prototype could look like this:
Now open the script editor and enter the following script. "
data.sum = data.valueA * 1 + data.valueB * 1
The script will read the user input from the first text field, which is saved in "data.valueA" and add the value of the second field ("data.valueB"). The result is written to "data.sum" and thus shown in the label.
Text fields return string values. You need to cast them to numbers, e.g. by multiplying with 1.