TQS Home
Trivia Quiz Shell Version 2.8 Now Available!Bot Productions Home
 

Part IX: Global Settings and Buttons

Up to this point, you may have noticed some things are getting somewhat repetitive. If, for instance, you want to scramble all of the answers for each Questions location you have, you have to add SCRAMBLEANS="1" to each QUESTIONS element. This section will introduce the concept of Global Settings, as well as how to use them.

Global settings are all contained within the GLOBAL element, a child of the TQS element. From there, there are several primary subelements: BUTTONS for specifying program-wide navigation buttons, elements corresponding to the different location types, MENU, QUESTIONS, and HANGMAN. (Note: TQS 2.1 adds the HTML element.)

The following code shows how to use the various global settings; they will be discussed in detail afterwards:

<?xml version="1.0"?>
<TQS VERSION="2.0" EDITABLE="1">
  <TITLE>My TQS Application</TITLE>
  <AUTHORINFO ... />
  <TQSWINDOW ... />
  <GLOBAL>
    <BUTTONS>
      <BUTTON ... />
      ...
    </BUTTONS>
    <MENU>
      <INSTR>Select an item.</INSTR>
    </MENU>
    <QUESTIONS SCRAMBLEANS="1" INORDER="1"
      SHOWSCORE="1">
      <CORRECT>Right answer!</CORRECT>
      <INCORRECT INSERT="@">Wrong! The correct
        answer is @.</INCORRECT>
    </QUESTIONS>
  </GLOBAL>
  <LOCATIONS START="0">
    ...
  </LOCATIONS>
</TQS>

Starting with TQS 2.1, virtually all settings can be specified at the local and/or global levels. However, TQS 2.0 has several limitations to where these attributes can be placed. For specific information on a particular setting, see the Reference.

When a setting is specified in global settings, an individual location can override it by specifiying its own value. Attributes set to "1" in the global setting should be set to "0" in an individual location if you wish to cancel the global setting.

The global MENU element can, in TQS 2.0, only specify instruction text to be displayed for each menu, through the INSTR element. In TQS 2.1, each MENU attribute is supported at the global level.

The global QUESTIONS element contains CORRECT and INCORRECT elements, which work just like in a location. The SCRAMBLEANS and INORDER attributes also work the same as introduced in Part VI of this tutorial. In TQS 2.0, the SHOWSCORES attribute can only be specified at the global level; in TQS 2.1 and newer, it can be set within specific locations' QUESTIONS elements.

The BUTTONS global setting is very powerful. Instead of explicitly specifying a Main Menu button in each location, you can place it in Global Settings and specify when it should be shown. This way, you can change the text of the button, for example, by just changing one element, instead of changing it in multiple locations.

Each button is controlled by a BUTTON element located inside of the global BUTTONS element. The syntax for several buttons appears below:

<BUTTONS>
  <BUTTON
    TITLE="Main Menu"
    TARGET="0"
    APPLIESTO="ALLBUT"
    EXCLUDE="0"
  />
  <BUTTON
    TITLE="Chapter %s Menu"
    SUBST="%s,LOCPOS:0"
    TARGET="LOCPOS:0,0"
    APPLIESTO="GREATER"
    GREATER="LOCPOS:1&gt;0"
  />
</BUTTONS>

The first BUTTON element contains two new attributes, APPLIESTO and EXCLUDE. The APPLIESTO attribute tells TQS when to display this button. If it is not specified, the button will never be displayed. It must be set to one the following: "NONE", "ONLY", "ALLBUT", "GREATER", or "LESS". As its name suggests, "NONE" will prevent the button from ever being displayed.

Setting APPLIESTO="ONLY" tells TQS to look for another attribute, INCLUDE, to find out which locations this button should be displayed in. The INCLUDE attribute consists of a semicolon-separated list of locations. For instance,

APPLIESTO="ONLY"
INCLUDE="0;1,4;3,0"

will cause the button to appear in Location 0, Location 1's Sublocation 4, Location 3's Sublocation 0.

If you set APPLIESTO="ALLBUT", TQS will do just the opposite. It will display the button in all locations except those specified in the EXCLUDE element. Thus, in the earlier code example, the Main Menu button would be displayed in each location but Location 0. Again, the contents of the EXCLUDE attribute must be a semicolon-deliminated list.

Using APPLIESTO="GREATER" or APPLIESTO="LESS", you can tell TQS to display buttons based on whether the location fits certain qualifications. When APPLIESTO is set to "GREATER", TQS will look for a GREATER attribute containing a logical expression to evaluate. When set to "LESS", TQS will use the LESS attribute. The logical expression must contain two numbers; however, most of the time you will want to use the LOCPOS dynamic value.

LOCPOS is a dynamic value which is used to specify the current location. If you have a location hierarchy nested two deep, the current location may be, for example, "4,2". LOCPOS is used with a colon to get an individual ID; for instance, LOCPOS:0 refers to the 4, the first ID, and LOCPOS:1 refers to 2, the second ID. If you have a complex nested location ID such as "15,4,23", LOCPOS:0 equals 15, LOCPOS:1 equals 4, and LOCPOS:2 equals 23. The number following the colon is a zero-based index of the specific component of the compound location ID.

Using LOCPOS in GREATER and LESS attribute expressions is easy. The earlier example specifies GREATER="LOCPOS:1&gt;0". The &gt; is used to represent a greater-than sign; for LESS, &lt; would be used. In the earlier case, the button will be displayed when the second ID segment of the location ID is greater than 0 (remember, LOCPOS starts at zero). Thus, the button will be displayed in locations to be used to return to an earlier menu.

The last thing that will be discussed here are the TITLE, SUBST, and TARGET attributes. The TITLE attribute, only when used within global settings, can contain a string which will be replaced with a value when it is displayed. The SUBST attribute has two purposes: one, it specifies the string from the TITLE attribute which is to be replaced; second, it specifies what it should be replaced with; in the case above, a LOCPOS value. A comma separates the text to be replaced and the text it is to be replaced with.

TARGET attributes can also use LOCPOS values. The example above will invoke location "x,0" whenever you are at location "x,1", "x,2", and so on.

Title and target substitution is helpful in creating large TQS applications. If you, for example, are creating a textbook and have organized a location hierarchy based on chapters, you can use the example syntax from above to automatically specify a button to return to a chapter menu. When the location is "2,1" or "2,2", the button will say "Chapter 2 Menu". Thus, you can populate dozens of locations with navigation buttons by only writing one line of code.

Global button settings can be confusing, but they are very powerful. For more information, see the Reference section, and look through sample applications.

This whirlwind tour of global settings concludes Part IX of the tutorial. Using global menu, questions, and buttons settings will make writing TQS applications much easier. At this point, you should have all you need to design powerful applications using TQS 2.0's built in features. However, if you are an advanced developer, you should read Part X to learn how to create your own custom TQS location types using HTML and scripting. Or, skip to Part XI to read about new features in TQS 2.1, 2.5, and 2.6.

Part X: Advanced Customization
Part XI: HTML Locations and the Data Root


©2016 Bot Productions. All rights reserved.Last Updated: May 28, 2004