In this example we have a car and our program has to check that, before the driver can move the car, the following conditions must be met:
Condition OK Value
Seatbelt is on 1
Doors closed 1
The car cannot be driven if the above are not all 1. But we also have an emergency option. This is normally 0 and is 1 in the event of an emergency, in which case the car can still be driven even if the other conditions are not met.
Program
---
Combined Any All example.
To be allowed to drive the car the /belt and /doors vars
must be 1. But if the /emergency var is 1 we can then drive
regardless of the /belt or /doors variables value.
---
prog_vars =
d/emergency 0
d/belt 0
d/doors 0
-- 1 = NO 2 = YES can drive
d/drive_ok 0
-- Test Message Array
d/test_message[3] ""
prog_vars.
prog_start =
pclear
-- Set the two test messages.
/test_message[1] "Cant Drive"
/test_message[2] "Can Drive"
-- Stop by default
/drive_ok 0
print "Car Drive Example"
prog_start.
prog_loop =
-- Test 1 > ALL OK Can drive
/belt 1
/doors 1
/emergency 0
do_drive_test
"Test 1 Result /drive_ok /test_message[/drive_ok]"
-- Test 2 > Cant drive no belt
/belt 0
/doors 1
/emergency 0
do_drive_test
"Test 2 Result /drive_ok /test_message[/drive_ok]"
-- Test 3 > Can drive despite no belt & doors because
-- /emergency is 1
/belt 0
/doors 0
/emergency 1
do_drive_test
"Test 3 Result /drive_ok /test_message[/drive_ok]"
exitprog
prog_loop.
do_drive_test =
-- Test all of the conditions and set the /drive_ok var
-- with the result.
any /emergency = 1 all /belt = 1 /doors = 1 ->
-- CAN drive
/drive_ok 2
else
-- CANT drive
/drive_ok 1
enda.
do_drive_test.
prog_stop =
print "Done exiting now!"
prog_stop.