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

Part V: Implementing Navigation Buttons

At this point in the tutorial, we have an application containing two hangman games, and a menu to choose which one to play. However, once a game has been started, there is no way to return to the main menu without quitting the program and starting over. Also, once you have cycled through all the words there is no other option besides quitting.

This section of the tutorial will solve these problems. TQS offers the space to the left of the About and Quit buttons to you, the author, to add navigation buttons. These buttons, when clicked, invoke a location that you specify.

Each LOC element has the ability to add buttons that are relevant to it. Thus, a BUTTON element is added inside of the LOC element to specify what button to add.

The following is the code for Location 1. Note the syntax of the BUTTON element:

<LOC ID="1" TYPE="HANGMAN">
  <HEADING>United States Hangman</HEADING>
  <BUTTON TITLE="Restart" TARGET="1"/>
  <HANGMAN>
    ...
  </HANGMAN>
</LOC>

For now, the only two BUTTTON element attributes that are of importance are TITLE and TARGET. The former specifies the text that appears on the button, while the latter tells TQS the location ID to invoke when the button is clicked. Since the target is set to the current location ID, it will, in effect, restart the current location.

We want to also be able to return to the main menu from each location. Therefore, we will add the following BUTTON element to each location:

<BUTTON TITLE="Main Menu" TARGET="0"/>

Buttons are added to the left of the About button from right to left, in the order specified in the TQS document. Thus, if you have the following code:

<LOC ID="1" TYPE="HANGMAN">
  <HEADING>United States Hangman</HEADING>
  <BUTTON TITLE="Restart" TARGET="1"/>
  <BUTTON TITLE="Main Menu" TARGET="0"/>
  <HANGMAN>
    ...
  </HANGMAN>
</LOC>

the buttons will be displayed in this order: Main Menu, Restart, About, Quit.

The concept of navigation buttons is not limited to restarting the current level or going to a menu. They can also be used to navigate to a related location. For instance, in our United States Hangman game, we could add a navigation button to take the user to a United States questions set, or any other related location.

For now, BUTTON elements must be added to each LOC element that uses it. We do not want our main menu to display any navigation buttons; therefore no BUTTON elements exist in the LOC element that corresponds to the main menu. In Part IX of the tutorial we will use global settings to specify navigation buttons which appear in each location.

Part V of the tutorial has added important functionality to our TQS application: navigation buttons which allow you to restart the current location or return to a previous menu. Navigation buttons can be used to navigate to any location existing in your TQS application. In the next part of the tutorial, we will dive into the third built-in location type, Trivia Questions.

Part VI: Adding and Customizing Trivia Questions


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