Screen Display

When a game is played using the web-based JACL interpreter, the output from each of the player's commands is returned in the form of a complete HTML page. These pages must be created by your game, including the HTTP header. The file frame contains two functions called +header and +footer that contain serveral write commands that output both the HTTP and HTML header for you. This means that in general you will only be required to display the command-specific response to each of the player's moves. Feel free to modify the +header and +footer functions to suit your desired presentation. For more information, see HTTP and HTML. When playing a game using TACL, all output from a game is written directly to the screen. Any HTML tags found will automatically be filtered out.

Write

The write command is the primary method of outputting all text. It will accept one or more parameters, each separated by a space. A parameter can either be plain text, a variable, a constant or an object pointer or label followed by a macro.

For example, the following command:

   write Hello, world!^

contains two separate parameters, the string Hello and the string world! (the comma after hello is considered to be white space.) When executed it will produce the following output:

   Helloworld!

This is obviously not the desired result. The correct way to print this familiar greeting is:

   write "Hello, world!^"

The reason for this demonstration of how not to print text is that it demonstrates how the write command operates. Each of the parameters after the write command is printed directly, one after the other. In the second example a single parameter containing both a space and comma is printed.
As with all other JACL commands, any single parameter that contains spaces must be enclosed in quotes. Failing to do this is a common cause of error.

Special Characters

When printing text, the write command recognises the following special characters:
Character Output
^ A caret will be translated into a newline. The TACL interpreter will not output any text until is reaches a caret. This is done to ensure correct word wrapping. When playing a game using JACL, this will manifest as carriage return in the HTML source.
~ A tilde will be translated into a double quote.

In most cases, when using the JACL interpreter, a newline printed using the caret character will be ingnored as whitespace by the browser. This extra whitespace can be of use to make the resulting HTML more readable.

The JACL interpreter will also print an implied newline after every write command. If this is not desired, the print command operated exactly the same as the write command except for the implied newline.
One place where the caret character is extremely important is the +header funtion of web-based games. An HTTP header is delimited by two blank lines that must be printed from this function. Failing to do so will prevent the player's browser from displaying the page.

Below is an example of the use of the tilde character:

   write "<p>~Hello,~ said the boy.</p>"
   write "<p>~Hello,~ said the girl in reply.</p>"

Each of these write commands prints a single parameter enclosed in quotes and together will display:

   "Hello," said the boy.

   "Hello," said the girl in reply.

Also note that the above write statements start with a <p> tag and end with a caret. The <p> tag is only required by JACL, but is filtered by TACL. The caret is only required by TACL, but is ignored by web browsers. Using both a <p> tag at the start of each paragraph and a caret at the end of each paragraph ensure that your game will run successfully using either interpreter. This is, of course, only true if you avoid using any HTML-specific features that can't safely be ingored by TACL.

Printing the Value of Variables

If the value of a variable is to be printed, as oppossed to verbatim text, the name of the variable must be entered as a separate parameter. For example, consider the following line from the +score function of the standard library — a write statement with five parameters:

   write "<p>Your score is " SCORE 
   write "% in " TOTAL_MOVES " moves.</p>"

The output of this five parameter command will vary depending on the current value of the two variables being printed. Typed as the very first command of the game it would display:

   Your score is 0% in 0 moves.

Printing the Value of Item Elements

The current value of object and location elements may also be printed using a write statement. This is done by enclosing the name of the element in brackets directly after then object's label. For example:

   write "<p>The dial is set to " dial(status) "Mhz.</p>"

Each object's elements are stored as a thirteen element array (0-12). A number between 0 and 12 can be used between the brackets as an index to the object element rather than it name. This is most useful when a variable is used in place of an absolute number in order to iterate through several elements. For a mapping of elements names to index numbers, see the section on definitions. Constants can also be defined as a way of renaming any given elements to a name that more clearly indicates its purpose. For example:

   variable INDEX
   constant fuel_left	2

   {+show_status
   write "

FUEL: " submarine(fuel_left) <br>^ set INDEX = 3 repeat write

INDEX ": " submarine(INDEX) <br>^ set INDEX + 1 until INDEX = 11 }

Printing the Name and Names of Objects

As you can see in the library file, is it a common need to print the short description of the object or objects that the player has referred to in a command. This is done using the noun1 and noun2 object pointers. When used during a write command, these object pointers may be followed by either a {the} or a {list} macro to display the object's short description. Given the following object:

     object wooden_box : small wooden box
       has          CONTAINER CLOSED CLOSABLE
       short        a "small wooden box"

if the player were to refer to this box as the first object in their command, then the write statement:

     write noun1{list}

would display, "a small wooden box", while

     write noun1{the}

would display, "the small wooden box".

If you require the output to be capitalised when using these macros, use {The} or {List} instead. For example, with noun1 still set to our box object:

     write <p> noun1{The} " is no good to eat.</p>"

will display, "The small wooden box is no good to eat."

Two other available macros, for use primarily in web-based games, are {names} and {+names}. These macros both output all the names of the specified object. The former prints a space before each name, while the later prints a plus sign before each name. These macros are used to make buttons that perform a set action on any unknown object. These buttons are either various input controls on HTML forms or hyperlinks. Names sent as the value of an input control must be separated by spaces. Names sent as a URL parameter of an hyperlink must be separated by plus signs. For example:

     write "<form>"
     loop
        write "<input type=~radio~ noun=~command~ value=~"
        write noun3{names} "~>"
     endloop
     write "<input type=~submit~>"
     write "</form>"

Like the {list} and {the} macros, these macros can be used with any object pointer or label.

Sentences Referring to Plural Objects

There are several other macros that may be used with the write command when coding the default action for verbs. They are designed to simplify the process of displaying the correct text for objects based on whether they have or haven't the attribute PLURAL.

Macro Output
object_label{does} Prints the word do if the object has the attribute PLURAL, or the word does if the object doesn't have the attribute PLURAL.
object_label{doesnt} Prints the word don't if the object has the attribute PLURAL, or the word doesn't if the object doesn't have the attribute PLURAL.
object_label{is} Prints the word are if the object has the attribute PLURAL, or the word is if the object doesn't have the attribute PLURAL.
object_label{isnt} Prints the word aren't if the object has the attribute PLURAL, or the word isn't if the object doesn't have the attribute PLURAL.
object_label{s} Prints the letter s if the object hasn't the attribute PLURAL, or nothing if the object does have the attribute PLURAL.

Special Tokens

Tokens are similar to constants, except they represent a text string rather than an integer. These are $url, $user_id and $text.

The first two are uesd exclusively in web-base JACL games. When used as a parameter of a write command, $url will display the location or URL of the JACL game, minus the machine name, while user_id will display the player's user ID. These two tokens are often used in combination when manually creating hyperlinks. Below is a example of the use of these tokens to provide a command that the player can perform with a single mouse click:

   write ";<a href=~" $url "?command=open+door&user_id=" $user_id "~>"
   write "Open door</a>"
It is very important in web based games that the player's user ID is passed with every move. This can either be as a URL parameter, like the example above, or as a hidden field in a form. See the section on HTTP for more information.

If the player enters a command that allows an arbitrary text string, this string can be displayed using the token $text. For example:

   grammar say $text >say

   {+say
   ifstring $text contains "microsoft"
      write "<p>Watch your language!</p>"
      break
   endif
   write "<p>You say, ~" $text ".~</p>"
   }

Centre

A centre command accepts a single parameter of plain text that is will display in the middle of the current row. If the game is being played using the JACL interpreter, the text will be wrapped in <center> tags. If the game is being played using the TACL interpreter, spaces will be inserted before the text based on the number of columns on the screen.

Look

A look command is executed internally by the JACL interpreter whenever a description of the player's current location is required. Namely this is when then player moves into a location for the first time or restores a saved game.
If the player has set the game to verbose mode (DISPLAY_MODE = 1), then a look command will be executed regardless of whether the location has been visited before or not.

The very first thing a look command will do is execute the global function +before_look. If this function exists, and does not break false, nothing more is done. If it does not exist, or does break false, then the look function associated with the current location is executed. After this has finished, the interpreter will display the text supplied by the long property for each object that is in the current location and doesn't have a mass of scenery.

If the long property of an object is the name of a function, that function will be executed. This is useful for descriptions that are either too long to fit in a single line of code or are dynamic. If the long property is not the name of a function, the property text is displayed verbatim.

The final step in the process is that the global function +after_look is executed.

It is convention to have a look command at the end of the +intro function so the player can see where they are and what objects are nearby when the game begins.

Console Presentation

When playing over the web, screen presentation is very dependant on the way the player's browser is sized. Re-drawing the screen, including tasks such as word wrapping, when the browser is resized is the responsibility of the browser itself. When playing a game from the console using TACL, however, the screen dimensions must be known, as all presentation is the responsibility of the interpreter. There are three main tasks that are dependant on these dimensions: word wrapping, centring text and displaying ---[MORE]--- prompts.

By default, the TACL interpreter presumes a screen with 79 columns and 25 lines. This can be changed by modifying the columns and lines directives in tacl.conf. For more information, see Internals.

There are also two presentation-related commands that are specific to the TACL interpreter: clear and more. A clear command will output a blank line for each line on the screen. A more command will display a ---[MORE]--- prompt, then wait for the player to press enter. After a more command, another full screen of text can be viewed before an automatic ---[MORE]--- prompt will be displayed.