Coffee Machine scenario SECTION 3 Advanced Tutorial
26
2. Select the storage tank for the coffee. Use the Workspace or Ungroup to
find the rectangular window and add a Percentage Fill (Vertical)
animation to the coffee storage tank viewing window with an expression
coffee_level and minimum of 0 and a maximum of 2000.
3. Repeat for the other storage tanks with the appropriate points for the
expressions.
4. Add an Edit Value (Analogue) animation to the button below the coffee
tank with an expression coffee_level.
5. Repeat for each button using appropriate point for each level.
3-1-6 Scripts
To extend the functionality we will add a Reset() subroutine for initializing,
make the coffee liquid and the cup invisible and set a text such as "Insert coin"
for the coffee machine display. This assumes the cup object, pouring coffee
and main display objects are called cup, coffee and Text_2 respectively. Either
adjust the script for your object names, or rename them in the Workspace to
these values.
3-1-6-1 Add the required points
1, 2, 3… 1. Open the Point Editor.
2. Add the points with details as listed in the table below. The Description
column is optional as it only helps explain to you the function of the point.
3-1-6-2 Add the script
1, 2, 3… 1. Open the Workspace Editor.
2. Right click Project Script and add a new Project Script.
3. Set the Trigger Event of the Reset subroutine with the following script
code to reset variables:
credit = 0
selection = 0
ready = TRUE
pressed = false
selection_made = false
main.coffee.visible(0)
main.cup.visible(0)
displaytext = "Insert Coin"
main.Text_2.blink( black )
4. On Main.pag add a Page Script with a Trigger Event of On Initialisation
to execute every time the page is loaded with the following code:
Now would be a good time to run the application by clicking the toolbar button
"Run the project" (or Project Menu, Run) and test that you can open and close
the machine, and add credit to the machine.
Point name Point type Default
Value
Description (optional)
pressed Boolean TRUE once first digit has been
pressed
ready Boolean Machine is ready to make a drink
selection_made Boolean TRUE when a selection has been
made