Using advanced math
In this recipe, you will learn how to use multiple math operations in a single line of LiveCode script. You will use operator precedence and nested operations. To facilitate this, we will use the common math trick where a person is asked to choose a number, and then perform the following operations on that number, the result always being 3
:
- Choose a number.
- Add 5.
- Double the result.
- Subtract 4.
- Divide the result by 2.
- Subtract the number you started with.
The result is always 3
How to do it...
Follow the steps in this recipe to program a multiple-step mathematical operation:
- Open LiveCode and create a new main stack.
- Set the background color of the default card to black.
- Drag a button to the card and set the following properties:
- Name:
btn_GetNumber
- Label:
Choose a Number
- Width:
122
- Height:
23
- Location:
71
,29
- threeD: Keep this unchecked
- backgroundColor: White
- Name:
- Drag a new text entry field to the card and set the following properties:
- Name:
fld_nbr1
- Width:
88
- Height:
31
- Location:
276
,23
- Font...
- Name: