Programming Simple Text Adventures on a TI-84 Plus Calculator
Wesley Olson
INTRODUCTION
The basic programming language on the TI-84 graphing calculator is an excellent starting point for aspiring programmers. Even if one isn’t a logic guru, this manual is designed to guide the student who has used the TI-84 in class for graphing and simple calculations to a linear word quest. The foundation for creating a unique adventure comes from knowledge of basic loop structure and variables, so these two topics will be covered briefly to encourage understanding of how the provided template (Figure 4) works.
|
VARIABLES
Variables are essential to creating a text adventure. Most students are familiar with the X,T,θ,n button for inserting the variable X into a function that will be graphed. There are 26 other variables that can be used by pressing ALPHA then choosing a button corresponding to the desired green character. To store a value to a variable, type an expression then press STO> and the variable. A great way to experience how variables work is to try typing in the following commands from the home screen of the calculator (the buttons pressed for each line are shown to the right):
|
Screen: Typed:
1->A
1
A+3
4
A+1->A
2
A2-1->X
3
|
1 STO> ALPHA MATH
ALPHA MATH + 3
ALPHA MATH + 1 STO> ALPHA MATH
ALPHA MATH x2 – 1 STO> X,T,θ,n
|
Note:
The variable X is obtained by pressing the X,T,θ,n button and the variable X obtained by pressing ALPHA STO> share the same value.
|
Figure : Using Variables
Note:
Make sure your calculator’s functions are in rectangular form (Y1=, Y2=, …), or the variable produced by X,T,θ,n will be one of the non-X variables.
|
WHILE LOOPS AND DISPLAY
While loops are powerful tools for doing something repeatedly as long as a statement is true. These loops begin with :While(*statement*) and always end with :End (colons depict the beginning of a new line in the coding). The statement has asterisks surrounding it to indicate that you can insert anything, and in this case it must be true or false. :Disp(*expression*) tells the calculator to show the value of an expression on the home screen. If only a variable is given, the value of the variable is displayed. :Disp(“*enter words here*”) will show any text as long as it is between quotation marks and less than 16 characters. To see how these work in conjunction with each other, open a new program (by pressing PGRM, scrolling over to NEW, pressing ENTER and entering a title) and try the following:
|
|
PROGRAM:*title*
:0->X
:While(X<5)
:Disp (X)
:X+1->X
:End
Running the program:
Prgm*title*
0
1
2
3
4
|
--:While is found under PRGM 5.
--For <, press 2ND MATH 5.
--For :Disp, press PRGM, scroll to I/O, and press 3.
--To run a program, press 2ND MODE to exit to the home screen, then press PRGM and select the program.
--This program will store zero as X, then display X and add one to X until X=5.
|
Figure : A While Loop With a Display
|
Screen: Notes:
|
|
WARNING!!!
:Disp(“*Message*”) will truncate your message to the first 15 characters with an ellipsis if it is longer than 16 characters (the horizontal capacity for the screen). An easy way to verify that a message is shorter than this limit is to check if any of the message’s characters are directly above another in the line of code. Use another display line if necessary.
|
PAUSE AND CLRHOME
To stop a code from continuing until the user presses enter, add the line :Pause to the code. It is found under PRGM 8. With a combination of this line and :Disp, one could write a story by displaying seven lines, pausing, and repeating with different text to the heart’s content. On the other hand, :ClrHome is typically an aesthetic addition; this line empties the home screen of all visuals and text. Many programs open with this line to remove unwanted text on the screen. It is found at PRGM I/O 8.
|
PROMPT
The difference between a text adventure and a story is that text adventures require user input. :Prompt X will ask the user to input a number to be stored as X. This line allows for multiple pathways in a story to create the most basic text adventure when used in conjunction with while loops. See Figure 3 for an example on how to use the prompt command in an actual adventure.
|
PROGRAM:DRAGON
:ClrHome
:Disp(“YOU’RE IN A CAVE”)
:Disp(“AND FIND A FIRE-“
:Disp(“BREATHING DRAGON”)
:Pause
:ClrHome
:Disp(“WHAT WILL YOU“)
:Disp(“DO?”)
:Disp(“(1): HIT IT WITH”)
:Disp(“A SWORD.”)
:Disp(“(2): RUN!”)
:Prompt X
:ClrHome
:
:While(X=1)
:Disp(“THE DRAGON”)
:Disp(“DEVOURS YOU!”)
:3->X
:End
:
:While(X=2)
:Disp(“YOU ESCAPE AND”)
:Disp(“CHOW DOWN ON”)
:Disp(“SOME DELICIOUS”)
:Disp(“MUTTON!”)
:4->X
:End
|
Notes:
--The apostrophe is found under 2ND APPS 2.
--To lock in ALPHA for faster text-typing, press 2ND ALPHA. To exit this mode, press ALPHA.
--“!” Is found under MATH PRB 4.
--Blank lines of code may make sections easier to recognize when looking at them later. These lines have no effect on the program.
-- the lines “:3->X” and “:4->X” are intended to escape infinite loops. Any value other than 1 or 2 will work.
|
Figure : A Simple Two Path Text Adventure
|
Running the Program Part 1:
prgmDRAGON
*screen clears on pressing ENTER*
YOU’RE IN A CAVE
AND FIND A FIRE-
BREATHING DRAGON
*screen clears on pressing enter*
WHAT WILL YOU
DO?
(1): HIT IT WITH
A SWORD
(2): RUN!
|
If 1 is Entered:
THE DRAGON
DEVOURS YOU!
|
If 2 is Entered:
YOU ESCAPE AND
CHOW DOWN ON
SOME DELICIOUS
MUTTON!
|
Continuing
To add more depth to this adventure, try adding more code to the end with “:While(X=4)” and more sections with multiple options. When running into errors, try referring to the compositions of previous sections. Figure 4 is a template based on the code from Figure 3.
|
PROGRAM:*title*
:ClrHome
:Disp(“*messages*”)
:Pause
:ClrHome
:Disp(“*messages*“)
:Disp(“(1): *event*”)
:Disp(“(2): *event*”)
:Disp(“(3): *event*”)
:Prompt X
:ClrHome
:
:While(X=1)
:Disp(“*messages*”)
:Disp(“(4): *event*”)
:Disp(“(6): *event*”)
:Prompt X
:4->X
:End
:
:While(X=2)
:Disp(“*messages*”)
:Disp(“(5): *event*”)
:Disp(“(6): *event*”)
:Prompt X
:End
:
:While(X=3)
:Disp(“*messages*”)
:7->X
:End
:
:While(X=4)
:ClrHome
:Disp(“*messages*”)
:End
:
:While(X=5)
:ClrHome
:Disp(“*messages*”)
:End
:
:While(X=6)
:ClrHome
:Disp(“*messages*”)
:End
|
Notes:
--Messages and events are interchangeable placeholders
--Adding or subtracting branches will change the depth of the adventure
--If incorrect responses from the user are an issue, try adding a different variable in each loop to call another loop.
|
Figure : Basic Text Adventure Template
|
Share with your friends: |