This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
howtos:toolcoding:common_history_and_background_checks [2010/09/14 16:14] marcus.williams created |
howtos:toolcoding:common_history_and_background_checks [2010/09/29 17:59] (current) marcus.williams |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | Many views require that a history be selected (if running in a simulator) | + | Many views require that a history be selected (if running in a simulator) and/or a background scenario be picked in. In these cases a section of code near the top of the view - following the object declarations - is used to check that the required history and/or background is in place. If not in place the code advises the user and quits. |
+ | |||
+ | Common code sections are listed below. | ||
+ | ===== Simulator - history and background required ===== | ||
+ | |||
+ | <code> | ||
+ | boolean $answer | ||
+ | if $history == false | ||
+ | say ("This view requires a history.") | ||
+ | listen (" enter to continue >> ",$answer) | ||
+ | quit (-1) | ||
+ | endif | ||
+ | if $background == false | ||
+ | say ("This view requires a background scenario.") | ||
+ | listen (" enter to continue >> ",$answer) | ||
+ | quit (-1) | ||
+ | endif | ||
+ | </code> | ||
+ | |||
+ | FIXME - do we have a best practice on the quit() return code? | ||
+ | |||
+ | ===== Simulator - both history and background optional===== | ||
+ | |||
+ | <code> | ||
+ | integer $index | ||
+ | $index = 1 | ||
+ | if $history == true | ||
+ | $index = $index + 1 | ||
+ | endif | ||
+ | if $background == true | ||
+ | $index = $index + 1 | ||
+ | endif | ||
+ | </code> | ||
+ | |||
+ | Note the use of $index for indexing the appropriate view. | ||
+ | |||
+ | ===== Simulator - history required, background optional ===== | ||
+ | <code> | ||
+ | if $history == false | ||
+ | say ("this view must be run with a history") | ||
+ | quit (1) | ||
+ | endif | ||
+ | |||
+ | integer $index | ||
+ | if $background == false | ||
+ | $index = 2 | ||
+ | else | ||
+ | $index = 3 | ||
+ | endif | ||
+ | </code> | ||
+ | |||
+ | Note the use of $index for indexing the appropriate view. | ||
+ | |||
+ |