Reading & Writing Data

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:

  1. Create two text fields and a label to show the sum.
  2. Select the first text field and set the data binding to "valueA"
  3. Select the second text field and set the data binding to "valueB"
  4. Select the label and set the data binding to "sum"
  5. Add a script widget to the canvas (use the cloud button in the topbar)
  6. 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.

Was this article helpful?

Programmatic Navigation
Script Basics & Intro