The place to discuss the ADRIFT Interactive Fiction toolkit

Beginner: Integer Variables - An introduction to numeric variables

This forum is the place to discuss the older ADRIFT versions 3.9 and 4.0.

Please refer to the ADRIFT 4 Manual for more information.

Postby MileOut » Wed Jul 03, 2002 11:59 am

What is a variable?

A quantity capable of assuming any of a set of values. A symbol representing such a quantity. For example, in the expression a + b = c, a, b, and c are variables.

Integers are numbers that are represented in a 'whole' format (e.g. 1, 5, 1000) as opposed to floating point numbers (e.g. 1.5, 3.125, 102.5).

Although in general programming an integer can assume a value betwen -32,768 to 32,767, ADRIFT allows integers to extend to higher - and lower - values.

To use a variable in ADRIFT it must first be 'dimensioned'. To do this you can click on the 'variable' button on the toolbar, or select the variable tab from the advanced section in the options menu.

On opting to add a new variable you will be prompted to give it a name. Giving you variable a meaningful name is advised as games can use numerous variables and can become confusing if you are naming them a, x, or gk12. If the variable will be used to hold a player's stamina, then PC_Stamina is probably a more convenient name. The PC part lets us know that the stamina refers to the player's character.

The second prompt you are required is to define a value for the variable. You, as the author can set this variable to be what you wish.

To use a variable in your ADRIFT creation you must reference it in a description. To reference the variable you must bookend it with % tags i.e %PC_Stamina%

Example - Putting a variable in a description

Create an object called coins that is held by player, and a variable called PC_Coins, set to 10. In it's description write "You have %PC_Coins% coins. Remember that ADRIFT is case-sensitive, so pc_coins would be different from PC_Coins.

Run the .taf and examine the coins. You should get the response "You have 10 coins."

Make a task called Get Money and make its action to change variable PC_Coins to increase by value 5. Ensure that the task can operate in the room, and that it's response is "You get 5 more coins."

Run the .taf and examine the coins. You will get the response "You have 10 coins." Type Get Money and you will be told that "You get 5 more coins.". Try examining the coins again. The response should be "You have 15 coins."


Try adding a further task called Lose Money whereby the coins are reduced by 5.

Edited By MileOut on 08 July 2002 at 13:14
User avatar
Posts: 410
Joined: Mon Jun 24, 2002 8:12 am
Location: Glasgow, Scotland

Return to ADRIFT 3.9 and 4.0

Who is online

Users browsing this forum: MSN [Bot] and 3 guests