Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Apple Guide Complete / Part 4 - Scripting Guide Files
Chapter 10 - Guide Script Command Reference / Guide Script Command Descriptions
/ Specifying Conditional Execution


<If>

You can use the <If> command to specify a condition that determines whether statements that follow it are executed.

<If> condition
condition
A condition function, either single or compound, that returns a Boolean value. Guide Script provides several built-in condition functions, such as radioButtonState and checkBoxState. You can also define your own condition functions using the <Define Context Check> command.
DESCRIPTION
You can use the <If> command, in combination with the <End If> command, to specify conditional execution of one or more commands. You can also use an <Else> command with an <If> command. Apple Guide executes the statements between an <If> command and an <End If> (or <Else>) command only if the condition evaluates to TRUE. Apple Guide executes the statements between an <Else> command and an <End If> command only if the condition evaluates to FALSE.

This is the general structure of conditional execution:

   <If> condition
      statement(s)      #executed if true
   <Else>
      statement(s)      #executed if false
   <End if>
You typically use conditional statements to dynamically adjust the sequence of panels presented to the user by specifying conditions that check the current state of user settings (such as radio buttons or checkboxes), other settings (such as the current date), or the state of the user's environment (such as whether a particular folder is open).

You can specify a single condition function or combine several condition functions into a compound condition using Guide Script's built-in compound operators AND, OR, and NOT; you can also use parentheses to further qualify the condition. For example:

#example of AND   functionA() AND functionB()
#example of OR    functionA() OR functionB()
#example of NOT   functionA() AND NOT(functionB())
#example of all   
         functionA() AND (NOT(functionB()) OR functionC())
The Standard Setup file defines various context checks (such as OpenWindow, InSystemFolder, and ControlPanelWinActive) that you can use to specify a condition in the <If> command (and also in the <Skip If>, <Make Sure>, and <Start Making Sure> commands).

SPECIAL CONSIDERATIONS
Every <If> command must be balanced with a corresponding <End If> command. You cannot nest <If> commands more than four levels deep.

EXAMPLES
<Define Sequence> "How do I create an index?"
   <Panel> "1st panel always display"
   <If> radioButtonState("Book Index", "1st panel always display")
      <Panel> "Panel 2 if true"
      <Panel> "Panel 3 if true"
   <Else>
      <Panel> "Panel 2 if false"
      <Panel> "Panel 3 if false"
   <End if>
   <Panel> "last panel always display"
<End Sequence>
<Define Sequence> "How do I create an index?"
   <Panel> "Index Choices 2"
   <If> radioButtonState("Book Index", "Index Choices 2")
      <Panel> "How do I create a book index?"
   <Else>
      <Panel> "How do I create a chapter index?"
   <End if>
<End Sequence>
<Define Sequence> "How do I create an index example 2?"
   <Panel> "Index Choices 2"
   <If> radioButtonState("Book Index", "Index Choices 2")
      <Panel> "Book index:intro"
      <Skip If> myCheckTemplateIsOpen("index")
         <Panel> "index template:open"
      <Panel> "Book index:create"
   <End if>
<End Sequence>
<Define Sequence> "How do I create an index example 3?"
   <Panel> "Index Choices 2"
   <If> radioButtonState("Book Index", "Index Choices 2")
      <Panel> "Book index:intro"
      <If> NOT myCheckTemplateIsOpen("index")
         <Panel> "index template:open"
         <Panel> "index template:create new"
      <End if>
      <Panel> "Book index:create"
   <End if>
<End Sequence>
<Define Sequence> "How do I add a word to the dictionary?"
   <Panel> "AddWords intro"
   #OpenWindow is a context check defined in Standard Setup file
   <If> NOT OpenWindow('WAVE', "Dictionary")
      <Panel> "AddWords open dictionary"
   <End if>
   <Make Sure> OpenWindow('WAVE', "Dictionary"), "SwContinueSeq"
      <Panel> "AddWords summary"
<End Sequence>
SEE ALSO
For information on the <Define Context Check> command, see page 10-172. For information on the <End If> command, see page 10-158. The <Else> command is described next.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
12 JUL 1996