Disaster
Jan 08 The TI-Nspire page is now finally complete containing documentation of the Nspire's programming capabilities and basic techniques.
Name: Gladiator Fight
Author: SpaceManiac
Download: Gladiator fight.zip
Compatibility: Parent page not set
File Size: 2225
A multiplayer turn-based strategy game in which 2-9 players compete for ultimate supremacy in a gladiator battle!

Member

Name: Pong
Author: SpaceManiac
Download: pong
Compatibility: Parent page not set
File Size: 950
This is a small game for the TI-83/84 series with basic pong physics and AI using the graph screen for graphics. It only supports human vs. calc modes however. I don't know if it includes any errors or stack leaks, and I know it could probably be optimized some more, so feel free to make modifications. It includes a pause menu and a secret cheat code.

This code is for monochrome calculators. For a color version, see here.

:AxesOff:FnOff :RectGC:GridOff:LabelOff:ZStandard:ZSquare
:Xmin+.5→A:"1X
:Xmax-.5→B:"2X
:"C/D:1/2Y
:"E/F:BX/Y
:2→G:2→H:"1/2W
:"J/K:BVX/Y
:"M:KEY
:0→N:0→O:"1/2PT
:"P:CPU DEST
:0→Q:0→R
:0→S:0→T:"1/2SV
:.5→U:"P2ACC
:Lbl R
:0→C:0→D
:0→E:0→F
:Repeat J≠0:randInt(-1,1)→J:End
:Repeat K≠0:randInt(-1,1)→K:End
:.7J→J:.7K→K
:While 1
:If Q=3:F→C
:min(Ymax-G,max(Ymin+G,C))→C
:F+2Hrand-H→P
:D+.27(P-D)→D
:min(Ymax-H,max(Ymin+H,D))→D
:Line(A,Ymin,A,Ymax,0)
:Line(B,Ymin,B,Ymax,0)
:Line(A,C-G,A,C+G)
:Line(B,D-H,B,D+H)
:Pt-Off(E,F)
:E+J→E:F+K→F
:If E>Xmax:Then
:N+1→N:Goto R
:End
:If E<Xmin:Then
:O+1→O:Goto R
:End
:If F>Ymax:Then
:Ymax→F:-K→K
:End
:If F<Ymin:Then
:Ymin→F:-K→K
:End
:If E>B and F≤D+H and F≥D-H
:Then
:T+1→T
:B-▲X→E:-J→J
:End
:If E<A and F≤C+G and F≥C-G
:Then
:S+1→S
:A+▲X→E:-J→J
:End
:Text(1,5,"P1:",N)
:Text(56,5,"SV:",S)
:Text(1,75,"P2:",O)
:Text(56,75,"SV:",T)
:Pt-On(E,F)
:getKey→M
:0→R
:If M=0:1→R
:If M=25:Then
:C+1→C:1→I:1→R
:End
:If M=34:Then
:C-1→C:1→I:1→R
:End
:If M=105:Then
:ClrHome
:Disp "PONG: PAUSED","{SCORE,SAVES}","PLAYER 1:",{N,S},"PLAYER 2:",{O,T},"PRESS ENTER"
:Pause
:1→R
:End
:If M=82 and Q=0
:Then
:1→Q:1→R
:End
:If M=41 and Q=1
:Then
:2→Q:1→R
:End
:If M=51 and Q=2
:Then
:3→Q:1→R
:End
:If M=45:Goto X
:If R=0:0→Q
:End
:Lbl X
:ClrHome
:Disp "THANKS FOR PLAYI","NG...","","   TI-84 PONG","","PROGRAMMED"," BY SPACEMANIAC"
:Pause
:ClrHome
:Output(1,1,""

Routine Summary

Shows the time, date, and day of week.

Calculator Compatibility

TI-84/+/SE

Author

2Tie

:getDate
:dayOfWk(Ans(1),Ans(2),Ans(3
:Disp sub("***SUN***MON**TUESWEDNES*THURS***FRI*SATUR",6Ans-5,6)+"DAY      //replace *s with spaces
:Disp getDtStr(getDtFmt
:Disp getTmStr(getTmFmt

First, the program acquires the date stored on your TI-84. Then it stores it and manipulates it to get the day of week. It then checks that and displays the result. Then it collects the formats to display the time and date.

Optimization

Although the program is already very small (about 122 bytes), you can make it smaller by shortening the day names to three letters each. This optimization would probably only benefit if you are including this in a larger program that you want as small as possible.

:Disp sub("SUNMONTUEWEDTHUFRISAT",3Ans-2,3

Error Conditions

This program should not generate any errors if coded right. It might display incorrect time if the clock is off. Use ClockOn if it is.

Related Routines

Member

Member

Member

PROGRAM:HELLOWLD
:ClrHome
:Disp "HELLO, WORLD!"

Jan 04 Zaphod Beeblebrox revamped the design page to be the development page and added the creating-new-program-versions article.

A stack is an abstract data structure that stores objects in a Last In First Out basis. The two main operations that can be performed on a stack are push and pop. Push adds an element to the top of a stack. Pop removes the top element from the stack, and returns it. A stack can be visualized as a stack of plates in a spring-loaded cafeteria stack. Only the top plate can be accessed, and plates can be placed onto the top of the stack, or removed from the top of the stack.

Stacks are used in virtually every computer architecture out there, in almost all operating systems, and in many higher-level programs as well. In fact, the TI operating system juggles two stacks (one for operations and one for numbers) to evaluate mathematical expressions, using a modified version of the shunting yard algorithm. And every time your program runs another program, a stack is used: to keep track of the programs to return to.

Reasons to Use Stacks

In general, stacks are frequently related to recursion — programs or routines that call on themselves again to do their jobs. In most modern languages, the use of stacks is hidden from the program through the use of local variables: variables that one program uses that another can't modify. In TI-Basic, all variables are global, and accessible to all programs, so you'll need to create your own stack almost every time you write a recursive program.

This is best illustrated with a classic example: calculating the factorial of a number N, written N! (there is already a factorial operation in TI-Basic, but pretend it doesn't exist for now). The factorial of N is defined recursively: N! = N*(N-1)! (with 1! and 0! being defined as 1). The actual code for a stack will be given in the next few sections; for now, let the fictional instructions Push(N) and Pop stand in for them.

prgmFACT

If N≤1:Then
1→F
Else
Push(N)
N-1→N
prgmFACT
Pop→N
FN→F
End
F

Here, the Push and Pop are necessary to save the value of N, because each time prgmFACT runs, it has a different value of N in mind.

Observe that the behavior of Pop isn't defined when the stack is empty. In fact, you'll see in the next section that most ways of implementing a stack will crash when you try to do that. In most cases, you can watch your code to make sure that pushes and pops come in pairs, to prevent this from happening — in the program above, each Pop has a corresponding Push. The only exception might be if you're trying to deal with user input (such as evaluating a mathematical expression) — in this case, bad input might cause this error, so you should always make sure to check if the stack is empty.

Implementation in TI-Basic

TI-Basic does not have a stack data structure by default, but depending on what needs to be stored, a stack can be implemented as either a list or a string.

Lists

You might consider two approaches to make a stack using a list: either the first element or the last can be considered the "top" of the stack. In practice, it's best to make the top be the end of the list — if it were at the front, the entire list would need to be shifted around in memory every time that an element got pushed or popped, which is much slower even for relatively small lists, and would get slower and slower for large ones.

To create the stack, just store 0 to its size: this will create the list if it doesn't exist, and make sure it has no elements in it.

:0→dim(L₁

Pushing to the stack is simple: to push a number N, the code is

:N→L₁(1+dim(L₁

This increases the size of the list, and stores N to the last element.

Popping of the list is done by getting the value of the last element and then decreasing the list size. This can be done with the following code:

:L₁(dim(L₁→N
:dim(L₁)-1→dim(L₁

If the stack is empty, this will cause an error: dim(L₁) will be 0, but L₁(0) is out of bounds.

Strings

The main difference between strings and numbers is that strings can be of any length. As a result, to separate the entries in the stack, we'll use a delimiter: a short string that will never appear in the entries of the stack. This delimiter will depend on what you're storing in the stack. In this code, we'll use the string "::" as the delimiter.

To create the stack, just store any single character (preferably not the delimiter) into the string you're going to use (we'd like the string to be empty, but empty strings aren't allowed in TI-Basic, so we'll go with the next best thing):

:"?"→Str0

For strings, we're going to think of the beginning of the string as the top of the stack — the reasons why will become clear later on. So to push an element to the stack, we're going to add the new data (Str1) to the beginning of the string, and a delimiter to separate it from everything else:

:Str1+"°"+Str0→Str0

To pop the data off the string, use the inString( function for find the first instance of the delimiter (this is why we're working with the beginning of the string — it's much harder to find the last instance). Everything before the delimiter is the element we're going to pop, but we want to remove the delimiter as well:

:inString(Str0,"°→N
:sub(Str0,1,N-1→Str1
:sub(Str0,N+1,length(Str0)-N→Str0

A critical observation is that this code depends on the length of the delimiter (in our case, it's 1). In general, for a delimiter of length K, replace the last line with the following (simplified, of course):

:sub(Str0,N+K,length(Str0)-N-K+1)→Str0

If the stack is empty, the string will contain no delimiters at all, so inString( will return 0, and an error will occur when we try to take sub(Str0,1,0). This gives a quick way to check if the stack is empty: just take the first line of the pop code.

toolbar-separator.png This article is part of the refreshing stage of the development cycle.

After you’ve published the first version of your program, your next consideration should be whether to embark on a different project or continue with your newly finished program. You need to decide whether your program is worth the updating, or it should be allowed to remain dormant. If you think you should update your program, you need to decide what should change about the program. What features you should, add what you should remove. This tutorial will help you in your considerations about this dilemma.

Making the Decision

After you make a program, give it some time to brew in the community, people need to be able to see a piece of software and work with it before they can handle another. If you barrage people with a new version every week, so that it is practically impossible to see the program before it is obsolete. The amount of time that you give to update will help you gauge whether or not updating is a good idea. The more time you wait you will receive emails with bug reports and suggestions, the download count will go up, and perhaps even reviews will be made of your program.
These can all be indicators that you should update your program. But the decision could be hard and here is a list of suggestions of what to think about when deciding to update:

  • Is your program being downloaded? There are two answers to this and two main ways of thinking about each. If it is not being downloaded, perhaps it was an effort that was futile and won’t work, or if you create a new version, the downloads will go up. If it is receiving downloads, then that is a sign that it is doing well and it is fine how it is, or you might think that the downloads might spike even more with an update.
  • Have you received emails about your program? Positive or negative, these are a good sign. If you have received them that means that the community cares about your project and finds interest in its development. This is usually a good factor in your decision.
  • Will your program benefit from and update? Think about your program, it’s speed, size, features, etc. Could you expand upon these? Did you have plans for features of your program that you never got around to implementing in the first version? If you believe could improve significantly from an update, then it is probably a good sign that you should update your program.
  • Will you benefit from updating your program? Let’s face it. You’re programming on a graphing calculator, your program is not going to be used for any truly serious purpose. That’s what computer programming is for. So the last question you should be asking yourself is whether you as the programmer will benefit and learn and expand from the new version. Will it challenge you and push your limits? If yes, than that is the last straw, updating is almost definitely a good idea. If not, don’t worry, find a different project that will incite your interest and push you to new heights.

After asking yourself these questions, time to make a decision. The last two questions are probably the most important in your decision. Even if your answer to the first two is no, it might just be because your program doesn’t have what it takes to make the limelight. It would then benefit from an update, making the answer to number three, a yes. Then you have to decide if number four is a yes. Whether four is important to you or not is your decision, but if it is it should be a large part of your decision.

How to Update

When you update your program there are several factors you need to consider about your updated program. What features you should add, and what to remove. What parts of the program run slower than you would like and how to remedy this.
Updating is difficult and to add onto that difficulty, often times large chunks of your code or even your whole program itself may have to be rewritten. But don’t despair, even if you do have to do rewrites, you have done similar coding before and can make it work better. Rewrites are recommended because the editing of current code has many downsides. Namely, it is difficult to do, and the end result tends to produce more bulky and poorly written code, than if the code was written from scratch and thought out from the beginning. Don’t worry if you have to start planning parts or even all of your program again, this is entirely natural. The better you make it, the easier it will be to update to future versions.
Time to decide what to keep and to remove.

Deciding on Features

Here are some tips on adding and removing features that the community will appreciate.

  • Listen to what people have told you and take it to heart. They are the community after all.
  • Remove features that are really glitzy and don’t add a whole lot to the program. Aesthetics are fine but don’t go too far. (e.g. People love good graphics, but grayscale is slow, unnecessary, and doesn’t look good in basic.)
  • Add features that are truly innovative and haven’t been done before. These are difficult to think of, but make the true selling point for your program.
  • Add the best features of other programs that are similar to your program. Idea sharing is perfectly legal, and most ideas are in the public domain anyways and can’t be claimed by any particular party.
  • Don’t add features that are going to weigh down your program. It’s not worth it.
  • Think about who you want to market this to, this will help you think about the portability of your program.
  • Above all, add features that are user-friendly. Usability is arguably the most important part of your program. Think carefully about your audience. Is it the average user who only knows how to send the program to their calculator? Is it an advanced programmer, using it to develop their own programs? This will help you gauge what your user-friendliness needs to be.

Think about these points and then write down a list of them, or whatever helps you remember and keep them catalogued. If you didn’t do this for the last version, do it now and draw some sort of chart, a flow chart for example, of how all the features of your program will link together and work together. Then you can start to really understand how it will work. You have essentially finished the planning stage. You can continue with more tips from the planning tutorial, but you can start to code.

After this, you are mostly done with the refreshing process. Now you can continue back through the development cycle and produce another version and then come right back to this article which will still apply. (You can most likely skip the planning stage, but it might not be a bad idea to look at.) This stage and decision whether or not to continue ends each loop of the development cycle.

<< Releasing Your Program Overview Planning >>
Name: PSADME
Author: Edward Hou
Download: Challenge6.8xp
Compatibility: Parent page not set
File Size: 599 bytes
Parses expressions using mixed-up precedence rules.

Member

C
Jan 02 Zaphod Beeblebrox added the Advanced Editing Functionality routine to the custominput page and added a xLIB key map to the key-codes page.
Jan 02 Congratulations Zaphod Beeblebrox for winning Challenge 6.

Member

Jan 01 Welcome 2009! Hopefully this year will be even more prolific for the TI-Basic Developer than the last.

Every command on the calculator is useful for programming, but some are expressly designed for that purpose. These are roughly divided into three categories: commands to control the flow of a program, commands to manage variables, and commands that provide input and output.

Control Flow

Any program is just a sequence of commands; but usually, it's not enough to just run through them all one by one in order and be done. Changes to this order have to be made: some commands should only be followed in certain situations, others might be repeated several times, still others might be a last resort in case of an error. Control flow commands are those that determine this order.

The simplest control flow commands are Goto and Lbl, which simply involve jumping around in the program. This isn't always the best way of doing things, though, and there are many alternatives:

Conditionals

A common situation is when certain commands depend on a condition being met. The following commands address this situation:

  • The If statement simply places a condition on a command or block of commands.
  • The Else statement, used with If, provides an alternative branch if the condition is not met.
  • The ElseIf statement, also used with If, allows for several mutually exclusive conditions.

Conditions are typically created by combining equality relations (=, , >, , <, ) with logical operators (and, or, xor, not).

Loops

Loops allow commands to be repeated over and over. The following types of loops exist:

  • Loop..EndLoop blocks just keep repeating forever.
  • While..EndWhile blocks repeat as long as a condition is satisfied.
  • For..EndFor blocks repeat a fixed number of times.

To deal with these loops, we have a couple auxiliary commands:

  • Cycle prematurely goes back to the beginning of a loop.
  • Exit leaves a loop ahead of time.

Subroutines

If a task has to be done several times inside a program, the code for it can be removed to a subroutine: this routine can then be "called" whenever necessary. Subroutines in TI-Basic are essentially programs of their own. They can be defined inside a program with the Define command, and are of two types:

  • Functions (defined with Func..EndFunc) return a value, and can't affect the overall state of the calculator.
  • Programs (defined with Prgm..EndPrgm) can do anything, but don't return a value directly.

Two commands exist specifically for use with subroutines.

  • Return exits a subroutine, returning to the program that called it.
  • Stop exits every program currently running, subroutine or not.

Error Catching

Error catching provides a last resort if an error occurs. A portion of the program, or even the entire program itself, can be put into a Try..Else..EndTry block. The code after Else will only run in case of an error, and has the option to ClrErr — go on as though nothing happened — or PassErr — handle the error normally, with an OS error message.

Variable Management

Another part of programming is managing variables. This means:

There is also the Local command, which designates certain variables as local to the program they are used in.

Input and Output

Finally, a program has to be able to get input from the user and give some output in response. For games, this usually means using the graphics commands, and reading keys with the getKey() command. There are other alternatives, however.

On the Program I/O screen:

A more stylish method is to use dialogs, wrapped in a Dialog..EndDlog box.

  • Input here is accomplished with Request and DropDown.
  • The Text command, appropriately, displays text. A Title is also handy.

Some miscellaneous commands remain. Custom..EndCustm and Toolbar..EndTBar both create toolbar menus with the help of the Title and Item commands. And PopUp displays a popup menu.

Input and output also refers to interacting with other calculators. There are five commands for the purpose:

Name: Trapped Beta
Author: Builderboy2005
Download: TrappedBeta2.zip
Compatibility: Parent page not set
File Size: 10079 Bytes
The Beta version of the new Trapped game. Ungroup the file and run ALEV to install. Then run A to play. Tell me what you think!

author: bxsciencer
description: 'This is the Solitaire Encryption algorithm that Bruce Schneier made for Neal Stephenson''s book Cryptonomicon. Before, only a TI89 version of the program existed. This is for the TI83/84s. Give your calc some time, and eventually something will come out encrypted/decrypted. The outputs are stored in Str1 and the decryption deck is stored in ∟DDECK.'
arcade: '0'
graphics: '0'
platform: '0'
puzzle: '0'
rpg: '0'
strategy: '0'
sports: '0'
casino: '0'
board: '0'
utility: '1'
misc: '1'
image: /home/no_image_2.png
download: SOLITAIRE.ZIP
size: '2964'
unit: '1'

Socks wrote:
comment A glass of milk (testing the system)

One of the most prominent features of the calculator is the Numbers Menu. This menu has many useful commands that can help ensure the cleanness of numbers, and they help with identifying list elements. Most programs use at least one of the commands in the numbers menu.

abs(

The abs( command simply finds the absolute value of a number. That is, it finds how many units away from zero a number is. So, the abs(5) is 5, and the abs(-5) is also 5. For programmers, this command means that any expression within an abs( will always be positive.

How is this command useful? Well, this command will make sure you have an expression that is always positive. It also allows for a check for two numbers. Since an equation with absolute value will give two answers, you can check for two solutions within a condition simultaneously. Observe the code for a condition.

:If K=21 or K=105

Using simple algebra and the abs( value command, we can actually solve for both with one equation. Find the median of the two numbers by finding their difference and dividing by two. (105-21)/2=42. Now, subtract that value from the larger number. 105-42=63. Now, if you add the 42 to the smaller number, you should also get 63. Now, using our rules about abs(, we can apply the numbers 63 and 42 to the conditional.
:If abs(K-63)=42

round(

The round( command will round a number to a specified decimal point. This command works well when you need a number to be a certain length. It also prevents rounding errors such as accidentally getting 3.0000000000012. This can cause domain errors, so it is sometimes better to use round( in case of irrational numbers.

iPart( and fPart(

iPart( and fPart( are very important commands when used together. iPart( takes the integer part of a number, where fPart( takes the fraction part. When together, you can compress the information of a coordinate into one number rather than two. This helps a lot with multiple objects that require moving.

Let's say that you want to store the coordinates of five different points. The points are in pixel format: (3,40), (24,9), (33,60), (12,22), and (50,20). You could store the points in 10 different real variables, which takes 180 bytes of memory. You could also store the 10 numbers in a list for 102 bytes. Or, with iPart( and fPart(, you make a 5 element list for 57 bytes, which is a lot smaller and easier to manage.

Store the first coordinate part (the y part) as an integer. Then, put a decimal point and have the x part as the number after the decimal. So, point (3,40) becomes 3.4, the point (24,9) becomes 24.09, and the point (33,60) is 33.6. Store it into L1 so that L1 becomes {3.4, 24.09, 33.6, 12.22, 50.2}. So, how do you turn 12.22 into (12,22)?

:Pxl-On(iPart(L₁(4)),100fPart(L₁(4)))

So, this code takes the integer part of the number and makes that the y part. Then, it takes 100 times the fraction part (to make it an integer) and makes it the x part. Now, you end up with Pxl-On(12,22).

How can you change it back? Simply retract the values and add them together.

:12+.01(22)→L₁(4)

int(

The int( command is very similar to iPart(. int( also finds the integer part, but it does so differently. iPart( simply gets the integer part, whereas int( simply rounds the number down. This only causes difference with negative numbers, where iPart(-5.5) yields -5, and int(-5.5) yields -6.

int( is commonly used to turn non-integers into integers. It is good to use this command if you want to ensure a number to not be fractional, such as when dealing with dimensions or coordinates. For example, if you have a variable, X, that represents the X location of an object and in the calculation, you divide by two, you will want to use int( so that the X doesn't have .5.

:X/2
:Pxl-On(12,Ans)
should be
:int(X/2
:Pxl-On(12,Ans)

min( and max(

These commands are very commonly used. You probably recognize them from the movement section.

min( finds the minimum value of two numbers or a list of numbers. max(, on the contrary, finds the maximum value. These commands are used as boundary checks for movement.

:min(16,max(1,B+sum(ΔList(K={24,26}))))

If the new value of B+sum(ΔList(K={24,26})) is less than 1, then max(1,0) will yield 1. If it is greater than 16, then min(16,17) yields 16. It never passes the boundary.

min( and max( can also be used to shorten a huge list of conditionals. For example:

:If A=21 or A=105 or A=45 or A=24 or A=26 or A=25 or A=34

Hmm, this can be shortened. min( and max( also find the minimum and maximum in lists. So, the min({1,0,1,1,0}) is 0. max({1,0,1,1,0}) gets 1. Here is how it works.
:If max(A={21,105,45,24,26,25,34})

So, let's say A is 25. That means we get max({0,0,0,0,0,1,0}) which is 1. If 1 is true, so it works. If A was 56, then we get max({0,0,0,0,0,0,0,0}) which is 0. If 0 is false, so the next command is skipped.

If you have a large list of or, replace with max(. If you have a bunch of and's, replace with min(.

<< Operators Table of Contents Powers and Exponentials >>
Name: Challenge 6
Author: Noahbaby94
Download: GUI.zip
Compatibility: Parent page not set
File Size: No size given
My entry for challenge 6

At some point during your programing you may come up with a need to search a list for a piece of data, search multiple lists for data, and use that data.

How to Search

Quick Search

This code takes use of the For( command and states whether or not the number is in fact in the list.
If you wanted to know what position in the list that number was, you can simply do that by recalling Z (Since Z is the interval it is going up by, it shows how far into the list the number is found)

:Prompt D                    //D is the number you want to find in the list
:For(Z,0,dim(L1               //Searches all the values up to the end of the list
:If L1(Z)=D
:Goto 1                        //If value is found in list, Goto 1
:End
:Disp "VALUE NOT FOUND"        //If Value wasn't found after the search, displays this
:Stop
:Lbl 1
:Disp "VALUE FOUND AT",Z        //If Value was found at the end of the search, displays text and location in the list where it was found
:Stop

Even Quicker Search

:if max(1/1+(abs(L-x)))=1            //L is the list, x is the value

First the searched value is subtract from every item in the list. Now if the value was in the list, it's now 0, so 1/1+0 is 1. Every other value results in a lower number.

Old Lengthy Code

Simple:

Using a loop you can search each point in a list and have it show you where it is in the list

PROGRAM:SEARCH1
:Lbl 0
:Prompt D            //D is the number you want to find in the list
:0→Z
:dim(L1→T            //T is "length" of list AKA number of points
:While 1            //Start of Loop
:Z+1→Z
:If L1(Z)=D            //if found
:Goto 1            
:If Z=T            //if not in list **(must be after above if statement)**
:Goto 2            
:End                //End of loop 
:Lbl 1
:Disp Z            //Tells you Placement in list (and the fact dose exist in list)
:Pause
:Lbl 5
:Menu("Now What","New Search",0,"Exit",4
:End
:Lbl 2
:Menu("Point Not Found","Store Point",3,"New Search",0,"Exit",4
:End
:Lbl 3
:D→L1(T+1)
:Goto 5
:End
:Lbl 4
:Stop    
:End

The above code is probably not fully optimized.

Two lists — More Advanced

In reality all you need to do is add the star(ed) .

PROGRAM:SEARCH1
:Lbl 0
**:Prompt X**
**:Prompt Y**        
:0→Z
:dim(L1→T            //both first and second list must be same length or the checked list must be the shortest        
:While 1        
:Z+1→Z
:If L1(Z)=X    **and L2(Z)=Y**        
:Goto 1            
:If Z=T            
:Goto 2            
:End                
:Lbl 1
:Disp Z            
:Pause
:Lbl 5
:Menu("Now What","New Search",0,"Exit",4
:End
:Lbl 2
:Menu("Point Not Found","Store Point",3,"New Search",0,"Exit",4
:End
:Lbl 3
:X→L1(T+1)
**:Y→L2(T+1)**
:Goto 5
:End
:Lbl 4
:Stop    
:End

The above code is probably not fully optimized

Not too hard, right?

More Complicated - Game use

So lets say you want to add "health" to that point you will need to add the star(ed) below .
Also at some point you will want to add the health to the points by doing :#→dim(L3)* and :Fill(100,L3)**

*# is length of list
**100 is heath

Note: does not show what was removed

PROGRAM:SEARCH1
:Lbl 0
:Prompt X        //if used for a game these prompts should **not** be necessary
:Prompt Y    
:0→Z
:dim(L1→T        
:While 1        
:Z+1→Z
:If L1(Z)=X    and L2(Z)=Y    
:Goto 1            
:If Z=T            
:Goto 2            
:End                
:Lbl 1
**:L3(Z)-10→L3(3)**            
**:if L3(Z)≠0**
**:Goto (you decide)            //Not dead and exists where to?
**:if L3(Z)=0**                
**:Then**
**:#→L1(Z)**                //Somewhere "out of the way" so that he is not "there" anymore
**:#→L2(Z)**
**:Goto (you decide)**        //okay hes dead now what are you going to do?    
**:End**
:End
:Lbl 2
**:Goto (you Decide)**        //no enemy is there now what?

The above code is probably not fully optimized.

The reason why this is difficult is because, well it requires a lot of thinking i can only show you a way but you must decide how it can be used.

Usage ideas

  • Multi-Hit Enemys
  • Level system (if (list)=# …. do ? damage)
  • Find data points
Name: "GUI Creator and Controller"
Author: Jonah Scheinerman a.k.a. Zaphod Beeblebrox
Download: Challenge6GUI-ZB.zip
Compatibility: Parent page not set
File Size: 2,082 bytes
This creates a GUI given an input matrix that can have text, title bar, check boxes, spinners, and text boxes and controls all the elements.
{$user} wrote:
comment {$comment}
{$user} wrote:
comment {$comment}

Add wish

The ListPages module does not work recursively.
Name: Peggle
Author: Builderboy2005
Download: Peggle.zip
Compatibility: Parent page not set
File Size: 7300 Bytes
Peggle is a fun and addicting physics based game. The game consists of 9 levels composed of several different types of blocks. You are given 9 balls to shoot into the arena to try to hit as many blocks as possible, resulting in them being erased at the end of a turn. If all blocks are erased, you proceed to the next level. Sophisticated scoring also allows for highscores to be made even if a level is not beaten. You can choose to play as one of 4 characters, each character having there own powerup accessible by hitting a special block. With challenging gameplay, stunning graphics, and great replayability, Peggle is a must for all calculator gamers!
Dec 15 noahbaby94 creates a chat room.

Chat removed. Some people were only using it to spam, and some to trick others who were asking questions into erasing their calculator's memory. Not the kind of behavior I was hoping to ever run into. –Weregoose

Name: Quadratic Factoring v1.1
Author: Timothy Foster
Download: quadfact1.1.zip
Compatibility: Parent page not set
File Size: 490 bytes
This program will factor quadratic equations equal to 0, and it can factor quadratic expressions. The program identifies GCF and prime quadractic polynomials.
Dec 14 The Programing challenge 6 has been postponed till 1/1/09.
Name: Xslider
Author: Noahbaby94
Download: Xslider.zip
Compatibility: Parent page not set
File Size: 1025
Have you played 15 square before? Well this is XSquare. You can create any size field between 2-5 for the length and 2-7 for the width. See the readme for more details.

or.png

Command Summary

Tests if either of two conditions is true.
Can also be used as a bitwise "or" on integers.

Command Syntax

condition1 or condition2
integer1 or integer2

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press 8 to enter the Test submenu.
  • Press 9 to select or.

Calculator Compatibility

This command works on all calculators.

Token Size

1 byte

The "or" operator combines two conditions into one, which will be true if either side is true, and false if both are false. You can create these conditions with the relational operators =, , >, , <, and , with functions such as isPrime(), pxlTest(), and ptTest(), or with any other expression that returns 'true' or 'false'. Other operators for dealing with conditions are and, xor, and not.

:2+2=4 or 1=0
           true
:2+2=5 or 1+1=3
           false

The operator can also be applied to integers, treating them as 32-bit signed integers (larger integers will be truncated to fit) expressed in binary. The bits will be matched up, and "or" will be applied to the bits individually — a bit in the result will be 1 if either of the two corresponding bits of the original integers was 1, and 0 otherwise.

:(0b11111100 or 0b00111111)▶Bin
           0b11111111
:256 or 512
           768

In complicated logical expressions (both with conditions and with integers), "and" has greater priority than the others ("or" and "xor"). For instance, X or Y and Z will be interpreted as X or (Y and Z).

Error Conditions

60 - Argument must be a Boolean expression or integer happens when the data type is incorrect (or mismatched).

Related Commands

See Also

delvar.png

Command Summary

Deletes a variable or variables.

Command Syntax

DelVar var1[,var2,…]

Menu Location

Starting in the program editor:

  • Press F4 to enter the Var menu.
  • Press 2 to select DelVar.

Calculator Compatibility

This command works on all calculators.

Token Size

3 bytes

The DelVar command deletes variables from existence, making them undefined again. This is a good way of cleaning up at the end of a program, or of making sure that a variable is undefined before you use it in a symbolic expression.

For DelVar to work, the variable must not be archived or locked. It also doesn't work on any program that's currently running, or on system variables.

There are two commands which might be a better alternative to DelVar, however. NewProb deletes all 26 one-letter variables at once; however, it also clears things like the graph screen that you might want to see preserved. Declaring a variable as Local at the beginning of a program prevents you from needing to delete it afterward, and it also makes sure you don't overwrite any existing variables.

Newer calculators have a DelType command to delete all variables of a certain type (provided they're not locked or archived). This is risky: you'll almost certainly delete too much. It's better to use DelVar, even if you have to list a hundred variables to do it.

Advanced Uses

Assembly programs might allow you to "hide" programs (or other variables) from the variable menu. This is actually done by marking the variable in question as "in use", the way a currently-running program is marked. As a result, you won't be able to delete a hidden variable, and trying to will give the "Variable or Flash application in use" error.

Error Conditions

140 - Argument must be a variable name happens when trying to delete something that isn't a valid variable name.

450 - Invalid in a function or current expression happens when DelVar is used in a function.

870 - Reserved name or system variable happens when trying to delete a system variable.

970 - Variable or Flash application in use happens when trying to delete a currently running program.

980 - Variable is locked, protected, or archived happens when trying to delete a locked or archived variable.

Related Commands

See Also

clrhome.png

Command Summary

Clears the home screen.

Command Syntax

ClrHome

Menu Location

This command can't be found in any menu besides the command catalog.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes

The ClrHome command clears the home screen — not the I/O screen where the result of commands like Disp or Output is displayed (you'd need ClrIO for that), but the screen where you run programs and evaluate expressions. This isn't usually something you want a program to clear, so this isn't a very exciting command.

It also has the drawback that the ClrHome command itself (or the program it's used in) is displayed on the home screen after it is cleared, so the end result is not a blank screen but something like what you see in the screenshot to the right.

Finally, ClrHome cannot be used inside a function, because functions aren't allowed to modify the state of the calculator.

Error Conditions

450 - Invalid in a function or current expression happens when ClrHome is used inside a function.

Related Commands

Dec 13 Do not forget about programming challenge 6. It has been postponed for a while now, and it will not end until at least two people participate. Also, challenge 7 will not start until number 6 finishes.

archive.png

Command Summary

Moves a variable from RAM to the archive.

Command Syntax

Archive variable, [another, …]

Menu Location

Starting in the program editor:

  • Press F4 to enter the Var menu.
  • Press 8 to select Archive.

Calculator Compatibility

This command works on all calculators.

Token Size

3 bytes

The Archive command moves a variable, or several variables, from RAM to the archive. This serves two purposes:

  • More RAM is now available for other variables.
  • The variable is protected from being edited or deleted.

On the 68k series of calculators, a variable in the archive can still be read (compare this to the behavior of TI-83 series calculators, where doing anything at all to an archived variable is forbidden). However, trying to store anything to the variable will give an error: it must be unarchived first.

Variables in the archive are also protected from being deleted. This means that a DelVar command called on it will cause an error. Commands such as NewProb or DelType that delete multiple variables will skip over any that are archived. Finally, in the event of a RAM clear (which is more likely to happen by accident than a total memory clear), archived variables will be preserved.

Any type of variable can be archived. However, you cannot archive system variables (such as xmin) or variables beginning with _.

Advanced Uses

It seems natural to archive programs, since they usually aren't written to, and they are valuable enough that you want to give them some protection. However, keep in mind that the first time you run a program after editing it, it gets tokenized — the text is converted into tokens that stand in for commands. The process might take several seconds.

If you edit a program and then immediately archive it, it is "protected" from this conversion process. That means that every time you run the program, it will be tokenized. To avoid this, run the program once to tokenize it, and then archive it.

Error Conditions

140 - Argument must be a variable name happens when archiving a system variable or an invalid variable name.

870 - Reserved name or system variable happens when archiving a variable starting with _.

960 - Undefined variable happens when archiving an undefined variable.

Related Commands

approx.png

Command Summary

Gives a decimal approximation of an expression.

Command Syntax

approx(expression)

Menu Location

While on the home screen:

  • Press F2 to enter the Algebra menu.
  • Press 5 to paste approx(.

Calculator Compatibility

This command works on all calculators.

Token Size

1 byte

The approx() command forces an expression to be evaluated in approximate mode, temporarily ignoring the mode setting. It's equivalent to pressing ♦ and ENTER when performing a calculation on the home screen.

:approx(π)
           3.14159265359

When applied to a complicated expression, matrix, or list, it approximates every number that occurs there.

Related Commands

Program Archives

The program archives is a stash of the various programs and games that can be downloaded from the computer onto your calculator.

The Routines

This is where most of the helpful code is. Routines will help you accomplish some tasks that cannot normally be done with a simple command. If you need help converting numbers to strings or adding the digits in a number, this is the place to go.

The ListPages module does not work recursively.

Alternate Routines

This page will show some alternate ways to do things to either gain a speed advantage, size advantage, or accomplish more than one thing. Sometimes, a simple routine won't do in a program, and this page will show you some new ways to accomplish the same task.

The Programs

A program will give an opportunity for input and for sure gives some sort of output. The programs provide examples of certain goals being met. These will also show you how to create input and output in crafty ways to help you become a more competent programmer.

The Games

The games here are very simple ones, but they use all of the design and techniques discussed in this wiki. These games are an example of what TI-Basic has to offer and how the techniques can be combined to create a full-fledged game.

Member

Tricks on the calculator. We've all been guilty of thinking, "Wow, it would be cool to screw up his calc." What? Only me?

Anyways, the only thing stopping you is knowledge. More specifically, the knowledge of how to do it.

The most basic trick is an infinite loop. Create a new program, call it whatever you want, and use the following code (Substitute the program's name for A):

:prgmA

But this is boring. Let's screw up their math.

:Input "",A
:Disp ArandInt(2,5
:prgmA

Note that both of these programs can be broken by pressing ON.

This page is for knowledge's sake only. We don't encourage you to try any of this, and we are not responsible if you do.

Member

Member

Dec 06 An announcements box is created.
Dec 06 It has been decided that the TI-Basic Starter Kit take priority in member contribution. Remember that the goal of the starter kit is to give a person of no programming knowledge a good solid start on calculator programming.

{$month} - {$day} : {$announcement}

ANNOUNCEMENT HERE

The ListPages module does not work recursively.

Add Announcement»

Member

Name: Timer
Author: HJTP
Download: Timer.zip
Compatibility: Parent page not set
File Size: 1500 bytes
A program containing a digital timer and a digital and analog clock.
Dec 03 graphmastur does not match any existing user name created a new page that allows you to upload files to use on any page. It can be found at the files page.

No files attached to this page.

Name: Timer
Author: HJTP
Download: timer.zip
Compatibility: Parent page not set
File Size: 1500
A timer which contains digital and analog clocks

Member

Member

The ListPages module does not work recursively.

This is a list of all the programs categorized as an RPG. These programs are ones that tell a story while you control a character.

This is a list of all the programs that cannot be specially categorized. These programs are none of the other categories, so this bunch of programs could be anything you don't expect.

This is a list of all the programs categorized as a Utility. These programs are tools that help you in given situations, from helping you design graphics to doing your laundry!

This is a list of all the programs categorized as a Board Game. These programs emulate the typical board games like Monopoly, Sorry, Chess, etc.

This is a list of all the programs categorized as a Casino Game. These programs use cards and dice to entertain your lucky side.

This is a list of all the programs categorized as a Sports Program. These programs have something to do with sports whether it be a game or helping tool.

This is a list of all the programs categorized as a Strategy Game. These programs are usually multiplayer which requires you to outsmart your opponent.

This is a list of all the programs categorized as a Puzzle Game. These programs provide a mind-bending experience as you proceed with solving problems and completing tasks.

This is a list of all the programs categorized as a Platform Game. These games are the ones that rely primarily on jumping, two dimensional graphics, and screen scrolling, much like Super Mario.

This is a list of all the programs categorized as a Graphics Program. These programs display stunning manipulation of the graph screen or else help you with making good graphics.

This is a list of all the programs categorized as an Arcade Game. These programs are usually simple, and yet they can be very addicting — Much like games you would find in a video arcade.

Dec 01 The Program Archives have been updated to include categorization.

What is interesting about today is that JamesKanjo has returned to his hovering project.
Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum Lorem ipsum.

The binomcdf( command calculates the binomial cumulative probability, either at a single value or for all values. This command can be used to replace seq( when used with cumSum(.

(Read more...)

Nov 30 Timothy Foster has been promoted to Moderator status.

The development of a program is essential to its ability to succeed and be good. The development is a cycle that can be repeated as many times as desired, each time making a new version. This cycle will allow you to make your program usable, efficient and clean. Here is a list of the parts of the development cycle and the parts of each.

Planning

Coding

Revising

Releasing

Refreshing

toolbar-separator.png This article is part of the coding stage of the development cycle.

There are various techniques you can use within your program in order to emulate different elements used in games and math. Here is a list of techniques you can use to accomplish all the elements of a good game and more.

The ListPages module does not work recursively.
<< Code Conventions Overview Commenting Code >>

If you feel that you have accomplished and mastered the art of programming, then the next step is to use that new skill in application. Test your knowledge with challenges and projects, and study professional routines and games to expand on what you know.

Review

This is a comprehensive test on your knowledge of TI-Basic. It contains questions with answers to see if you are knowledgeable in the arts of programming.

Challenges

These are the programming challenges that are put forth by other members of the community. Try your hand at the grueling dares by creating a program that best fits the criteria.

Project Ideas

These are some of the project ideas to help you get started on some major programming stuff. If you need an idea or illumination, then try this corner.

Projects

Here are some projects currently going on here at TI|BD! Feel free to participate in these community oriented programming projects.

Routines

These quick chunks of code allow you to get through your programming without the hassle of inventing something already invented. These are optimized and ready for you to use them, of course whenever you need it.

Programs

A program will give an opportunity for input and for sure gives some sort of output. The programs provide examples of certain goals being met. These will also show you how to create input and output in crafty ways to help you become a more competent programmer.

Games

The games here are very simple ones, but they use all of the design and techniques discussed in this wiki. These games are an example of what TI-Basic has to offer and how the techniques can be combined to create a full-fledged game.

Member

Member

Nov 28 The home page has been revamped and the top and side bars have been switched to provide a fresh look to the site.

Member

Name: Blackjack 2.14
Author: Ray Wang
Download: blackjack_v2.zip
Compatibility: Parent page not set
File Size: 5361 bytes
This originally started out as a simple text-based version of Blackjack that I made, until I figured out how to get graphics working BASIC programs. Now includes betting and an auto-money-saver-type-thing.

The If command is used to determine what path of action gets done depending on a condition. With this command, you can set If…Then or If…Then…Else blocks for the calculator to interpret.

(Read more...)

Name: BC's Beta Tetris
Author: ibly31
Download: BC's Beta Tetris
Compatibility: Parent page not set
File Size: 2334 Bytes
Fun beta Tetris in a small package!
The ListPages module does not work recursively.
Getting Involved

A site can only grow and thrive through the continual efforts of its members. If you have found this site useful, we encourage you to contribute and become part of our community.

Sign-ups are available, and our forums are open to questions, commentary, or anything else that you want to talk about. We hope to see you there!

Forum Activity
Hello! Iam currently messing around with a project that require me to convert hex to binary. So i...
(by crossti 25 Feb 2018 14:19, posts: 1)
I meant that you were new to the TI-Basic Developer, as you created an account pretty recently. I...
(by Myles_Zadok 24 Feb 2018 18:48, posts: 5)
Hello How it works … Thank you
(by xavi6 24 Feb 2018 15:28, posts: 2)
Did You Know...
The ListPages module does not work recursively.
Top Rated Programs
The ListPages module does not work recursively.
Featured Article
The ListPages module does not work recursively.
Featured Command
The ListPages module does not work recursively.

Welcome to the TI-83 section of TI-Basic Developer (TI|BD)! This section of the site covers how to make TI-Basic programs for the TI-83, TI-83+, TI-83+ Silver Edition (SE), TI-84+, and TI-84+ Silver Edition calculators (often abbreviated as TI-83/84/+/SE). After going through all of the TI-83 information, the reader should be a competent TI-83 Basic programmer.

Image Here

Site Content

Search

We've tried to create a broad base of TI-Basic information. This ensures that most readers will hopefully be able to learn something from this site. Experimentation is encouraged to fully digest all of the information.

Please use our search engine to find what you desire, or refer to the sitemap.

Each reader can read the information in whatever order they desire. For the average reader, though, the suggested approach is to just start from the beginning and read until the end. The information is presented in a sequential order, with the concepts and code getting increasingly more complex as you get further into it. You might also look at the page Using This Guide, which outlines another suggested reading order.

Please feel free to not only get involved, but also come back often to see what changes or additions have been made. And above all else, enjoy your stay!


Recent News

TI|BD is constantly changing through the efforts of its members. Here are the most recent significant edits that have been made. For the complete documentation of the history, see News Depository.

The ListPages module does not work recursively.

If you have made a significant modification, made a new page, or contributed to this site in another way, please document what you did by adding news.


Portable Guide

As a part of this site's growth, we have created a portable guide for you to print out and have as a programming source wherever you go. The portable guide contains most of this site's content in a printable format including all the commands, techniques, and calculator references.

Go to the Portable Guide for TI|BD.


New Members

It is only by our members that this site can grow. Welcome to the new members who have joined TI|BD:

The ListPages module does not work recursively.
Nov 25 We receive news that the TI-Basic Developer, after two years of hard work and effort by its members, has become a popular site within the Wikidot community, the site that hosts this wiki and many others. This represents a major turning point for TI-BD.
Name: U.S. Presidents
Author: patriotsfan
Download: U.S. Presidents.zip
Compatibility: Parent page not set
File Size: 10628 bytes
This program contains all United States presidents and info on each of them. It is great for History class!
Name: Slideshow 83+
Author: Basickevin
Download: Slideshow.zip
Compatibility: Parent page not set
File Size: 1992+767 per slide
The ultimate slide editor, viewer, and slideshow presenter. Allows for complete manipulation of any picture you want to view and easily allows for cool little presentations. Includes design templates and clip art.
Name: Yahtzee
Author: 7thAce
Download: Yahtzee! v1.2.zip
Compatibility: Parent page not set
File Size: 4100
A Casino game where you roll 5 dice three times and try to accumulate the highest score with your rolls. Played on the graph screen
Nov 21 A new members system is used for members which gives each member a profile page.
Name: Dot Mania 1.40
Author: Rhombus p.
Download: Dot Mania 1.4.zip
Compatibility: Parent page not set
File Size: 4857 bytes

this program includes three games that has every thing to do with dots

New in version 1.4

  • Smaller
  • Faster
  • New Splash Screen

New in version 1.3

  • Runs Faster!
  • Size reduced by 600 bytes
  • bug fixes!

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Admin

WAC

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

A

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

C

Member

Member

Member

Member

C

Member

Member

Admin

WA
userkarma.php?u=260544&onlyKarma=truea48.png Recipito (profile)

Joined Mar 23


Time Zone: Not given

Member

Member

Member

Member

Member

Member

C

Member

Moderator

Member

Member

Member

We are dealing with a graphing calculator after all, so it makes sense that there are lots of graphics commands to talk about. Although the graphical capabilities of the calculator are limited (a monochrome LCD with either 160x100 or 240x128 resolution) these commands allow programmers to squeeze everything out of the screen that they can.

This page is divided into two sections: "Drawing commands" for general tasks like drawing lines, circles, or individual pixels, and "Graphing commands" which deal with the graphs of various functions. If you're not interested in the math aspects of graphics, you might want to skip the second section, especially at first reading.

However, all functions discussed on this page share a common aspect: their difference from normal graphing. When an equation variable is graphed, the result is semi-permanent: using a command like ClrDraw to clear the screen, or changing some setting, can do nothing more than cause the graph to be redrawn. However, all of the commands on this page produce "drawn items" which disappear permanently when the screen is cleared.

Drawing Commands

If you want to draw an image on the screen, you have two choices. First, you can build it up from simple shapes like dots, circles and lines. This may work great for an user interface, but it pretty much limits you to stick figures when you want to draw anything more complicated. So the other option is to have a picture already stored in a variable, and just display it to the screen as you need to. We'll cover both of these in order.

A universally useful drawing command is ClrDraw: this clears everything drawn on the graphscreen.

Point vs. Pixel

TI-Basic allows two ways of specifying a location on the screen: "point" coordinates and "pixel" coordinates. The point coordinates are the ones that you see most often: they are the coordinates determined by the graphing window, with (xmin,ymin) being the bottom left corner and (xmax,ymax) the top right. Because the graphing window has to be initialized if you want to use these in a logical way, this is NOT usually the best type of coordinate to use.

The alternative is pixel coordinates ("pixel" refers to the individual dots that make up the calculator screen). The graphscreen is made up of 77 rows and 159 columns of pixels, and 103 rows and 239 columns on a widescreen calculator (this ignores the rightmost column of pixels, which can't be drawn to). So the pixel coordinates refer to each pixel by the pair (row,column). This is actually the reverse of the point coordinates: the first number determines the vertical location, and the second number the horizontal location. The rows and columns are numbered starting from 0, and the 0th row is the top row. So (0,0) refers to the top left pixel of the graphscreen, and (76,158) or (102,238) refers to the bottom right pixel.

For pretty much every drawing command, you have to specify a location on the graphscreen at which to draw. You can choose either type of coordinate (although your life will be simpler with pixel coordinates) — for every point command, there's a matching pixel command, and vice versa (with an exception we'll get to later).

For example, you can draw a line with the Line command, and the syntax will be:

Line x1,y1,x2,y2

Or you can use the PxlLine command, with the syntax:
PxlLine row1,col1,row2,col2

The following table gives you all the simple drawing commands in their two forms:

Point Coordinates Pixel Coordinates
Circle PxlCrcl
Line PxlLine
LineHorz PxlHorz
LineVert PxlVert
PtChg PxlChg
PtOff PxlOff
PtOn PxlOn
ptTest() pxlTest()
PtText PxlText

Sprites

Using picture variables, you can store a rectangular image of any size, to be displayed on the screen later. In video game language, such an image is often called a sprite.

The several commands that deal with picture variables are covered in-depth in the Sprites article (CyclePic is described in the Animation article because, you guessed it, it lets you display an animated image). One important thing to note is that they only use pixel coordinates — another reason to use these.

The seven sprite commands are:

Graphing Commands

The usual way of graphing is to store to an equation variable such as y1(x), and then simply go to the graph screen (where you can resize the window and other fun stuff). For the convenience of programmers, any sort of graph manipulation you can choose from a menu is also available as a command. The 68k calculators also provide another way of graphing, probably more suitable to programmers, which draws a graph of a specific expression.

Graphing Expressions

These simulate graphing an equation from any graphing mode. Of special note is the Graph command — unlike the other commands, which can be erased with ClrDraw or any other way of refreshing the screen, the output of Graph can only be erased by ClrGraph or by going to the Y= screen to re-enable the normal Y= functions.

Zoom Commands

The zoom commands resize the graphing window determined by xmin, xmax, ymin, and ymax. For the most part, these four variables are all they change. The exception is ZoomStd, which restores certain other values to their defaults, and ZoomSto and ZoomRcl, which back up and restore all window variables.

Graph Manipulation

These final commands are more or less miscellaneous. Their uniting characteristic is that they deal with the graph of an actual equation variable (the ones you edit in the Y= screen). Of these, FnOff is probably the one to remember: it turns off all equation variables without actually deleting them.

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Member

Moderator

Member

Member

Member

Member

Admin

WF

Member

Member

Member

Joined Sep 07 noahbaby94noahbaby94

Time Zone: -6 GMT
Birthday: 09/02/1994

How I Found TI-Basic Developer

Looking for a way to convert numbers to strings.

How I Began Programming

Math class needed to know how to program.

Best Program: Quadratic

Member

Member

Member

Member

Member

Member

Member

Member

Member

Admin

W

Member

Admin

Member

Admin

FWDAC

Time Zone: Not given


Time Zone: {$timezone}
{$birthday}

{$aboutme}

{$howifoundtibd}

{$howibeganpgrming}

{$hobbies}

{$mybestprogram}

Joined {$month} {$day} UsernameUsername

char.png

Command Summary

Returns a character given its ASCII code.

Command Syntax

char(code)

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press D to enter the String submenu.
  • Press A to paste char(.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes

The char() command converts an integer between 0 and 255 to the corresponding character in the calculator's internal code (which is a modification of ASCII). It can also operate on a list or matrix by converting each of their elements to a character.

This command, and its inverse ord(), can be useful for programs that deal with arbitrary strings (which could, potentially, contain any character), but they can come up in other cases as well. For example, since the letters A..Z are consecutive characters in the calculator's internal code, with A being char(65), you can calculate the nth letter in the alphabet with the expression char(n+64).

There are two special values of char() to be aware of. The character given by char(0) is actually the empty string, which you usually want to avoid using; the character given by char(13) is a newline "enter" character, which is replaced by ":" when you type it somewhere. If you actually want to store char(13) to a string, you have to use the char() command.

Advanced Uses

TI-Basic does not allow lists to contain picture variables, and in many cases (such as tilemaps) you want to get around this limitation. One way to do so is to name the variables "tile1", "tile2", "tile3", and so on, with only the number changing — then #("tile"&string(n)) gives the nth picture variable.

A more efficient way is to assign the pictures numbers in a different range, such as 65-90, and name the variables "tilea", "tileb", "tilec", etc. Then, #("tile"&char(n)), which is faster, converts a number to the corresponding picture variable. This allows for a maximum of 146 different tiles, if you use all the characters that could conceivably be part of a variable name.

Error Conditions

260 - Domain error happens when the character code isn't in the range 0..255.

Related Commands

See Also

mid.png

Command Summary

Selects a substring from a string, or a sublist from a list.

Command Syntax

mid(string-or-list,start[,count])

Menu Location

  • Press 2nd MATH to enter the MATH popup menu.
  • Press D to enter the String submenu.
  • Press 5 to paste mid(.

Calculator Compatibility

This command works on all calculators.

Token Size

2 bytes

The mid() command can be used in two ways: to select a sublist from a list, or a substring from a string. In both cases, the syntax is similar:

  • the first argument is the list or string to start with.
  • the second argument is the number of the first element or character to include,
  • the third argument is how long the sublist or substring should be.

That is, mid(list,x,y) will give a list of the xth element, (x+1)th element, and so on up to the (x+y-1)th element of list. If x=2 and y=3, this will give a 3-element list starting from the 2nd element.

:mid({1,2,3,4,5},2,3)
    {2 3 4}

For strings, mid(string,x,y) will give a y-character-long string starting from the xth character of string:
:mid("TI-Basic",2,5)
    "I-Bas"

In practice, the mid() command is rarely useful for lists, although it might occasionally come in handy. It really shines with strings, since there is no other way to select a character from within a string. Whereas you might use list[5] to select the 5th element of a list, with a string you have to write mid(string,5,1) to get that single character.

A noteworthy feature of mid() is that out-of-bounds indices don't cause an error. If the length you give for the substring or sublist is more than the number of remaining characters or elements, then it will give you as many as there are, instead. If the value of start happens to be past the end, then the output will be a null value: the empty list {} for a list, and the empty string "" for a string.

Optimization

The third argument — the length of the sublist or substring — is optional if you want to include everything past the first element or character. For example:

:mid({1,2,3,4,5},3)
    {3 4 5}
:mid("TI-Basic",4)
    "Basic"

In this case, the result is the same as the result of right(), but the input is different.

Furthermore, if you're always going to start at the beginning of the string, left() is a better alternative to mid(): left(var,x) is equivalent to mid(var,1,x), and saves you a total of 3 bytes.

:mid(str,1,5)
    can be
:left(str,5)

Error Conditions

260 - Domain error happens when start isn't positive, or count is negative.

Related Commands

Name: The Classroom
Author: ibly31
Download: Classroom.8xp
Compatibility: Parent page not set
File Size: 4 KB
The game from AddictingGames is here, on the calculator. BETA VERSION
toolbar-separator.png This article is currently in development. You can help TI-Basic Developer by expanding it. Do we need this page?

There are four main operations on the calculator that are used widely in programs. They are the simple addition, subtraction, multiplication, and division. Although these simple operators are used for simple application, they can be very useful when utilized in advanced matters.

Addition

Addition is the first operator. Mostly, the addition operator is used to combine the values of variables or to increase the value of a variable. It can be used as a counter as well. However, the addition operator can also be used to increase values in lists and combine strings. When applied to lists, you can manipulate sprites.

Addition can be used to move sprites. Well, no duh… Think of this. In the previous chapter, you learned of text sprites. They are typically a coordinate and at that coordinate, text is displayed to simulate a sprite. However, addition can be used to move the pixels with a list. This leads to the discussion of Stat Sprites.

A Stat Sprite is a sprite whose individual coordinates are stored into L1 and L2. When you turn Stat Plot 1 on, the sprite is automatically displayed onto the graph screen. Addition can move this sprites really easily. When you add a constant to a list, the calculator distributes that value across the entire list. So, instead of adding each individual pixel, you can add the whole list.

:1+L₁
:1+L₂

Subtraction

Subtraction is a powerful tool being the opposite of addition. Although the subtraction operator cannot be used with strings, it can often replace addition. This operator can be used as a countdown. You can also subtract from lists just like adding.

Multiplication

Multiplication determines the product of two numbers. For example:

5*3
      15

TI-Calculators also use implied multiplication for variables by putting them next to each other. This can be handy and simplify math but it means that, unlike most programming languages, only single letters can store a value–Multiple letters are interpreted as each value being multiplied.
4*A is the same as 4A.
3→NUM Returns an error.
NUM is interpreted as N*U*M

Division

Division is the opposite of division. It is shown with a slash (/)

18/9
      2

Fractions also use division. If you are in MATHRINT mode on the home screen, it looks like a fraction while otherwise it looks like a bold slash.

<< Introduction to Math Table of Contents Numbers Menu >>
toolbar-separator.png This article is currently in development. You can help TI-Basic Developer by expanding it.

The Text( command is very helpful for graphics on the graph screen. It can be use to make Text Sprites, and to display information that can be more customized than the home screen. To use this, you use the syntax: Text(X Position,Y Position, Variable). The variable can be any data type.

Displaying Text

Let's say you want to tell the user that they're score was 10. you would use this code:

:Text(1,1,"Your Score Was:10")

Since this is on the graph screen, you don't have to worry about a limit as much. The horizontal limit is 94 pixels, and the characters are smaller.

However, games usually have variating scores. You can use this code to display the player's score, A.

:Text(1,1,"Your Score Was:",A)

Larger Text

There is an additional argument ,-1, that goes at the beginning of the command. -1 is the difference between 5*3 Graph screen text and 8*5 Home screen text. So lets say your making a title page, and you want it to say "My Home Page" at the top in big letters, and beneath that the information in small letters, you would use this:

:ClrDraw
:Text(-1,0,0,"My Home Page")
:Text(10,1,"This is my testing homepage.")

Text Sprites

Note: If you are using a TI-84+CSE or TI-84+CE, the increased resolution makes working with Text Sprites very challenging. Many of the techniques described in this section may not function properly.

Text sprites are a way of showing a character or piece of background. They are mainly used for puzzle games, that draw the playing field once, like Donut Quest by Mikhail Lavrov.

A text sprite uses Text( in order to display a little icon. Here is the general code.

:For(A,1,7)
:Text(0,A,sub(string,A,1))
:End

The string is a 7 character string with the first five characters representing the object and the last two being spaces. What happens is every time the For( loop is executed, the text moves one to the right and the next character in the string is displayed. It ends up overwriting the previous text except for its first row. If you don't understand this yet, you may want to throw a Pause in the code to see the sprites drawn step by step.
:For(A,1,7)
:Text(0,A,sub(string,A,1))
:Pause
:End

So, let's say you want to draw a donut. What would the string be? First, draw a five by five grid and outlay your donut.

0 1 1 1 0
1 1 1 1 1
1 1 0 1 1
1 1 1 1 1
0 1 1 1 0

Now, take notice on where the ones are. Look at the first column. The middle three pixels are on. What character has its first row in the same pattern? Let's try (.
0 1 0
1 0 0
1 0 0
1 0 0
0 1 0

Look! Same first rows! So, a ( would be the first character. For the donut, you want the string to be "( [ X [ ( _ _". When this is put into the code, you make a donut shape. This can be done with most five by five designs.

Try making this one.

0 0 1 0 0
0 1 1 1 0
1 1 0 1 1
0 1 1 1 0
0 0 1 0 0

Can you make the appropriate string?
<< Drawing More Shapes Table of Contents Using Pictures >>

Now that you know how to utilize both the graph screen and the home screen, the next step to making wonderful programs is learning how to use the math. That's right: math. Most programs have to use math in order to run. Games that include gravity are an example. The math functions are pretty straightforward; however, their effective use requires some masterful skill. Understanding the math functions will bring you one step closer to becoming a master programmer!

Basic Operators

The simplest operators include +,-, *, /. This tutorial will show how these simple arithmetic operators can be very powerful when applied effectively.

Powers and Exponentials

This group includes all the commands that deal with exponentiation, like ^, 10^(, EE, and e^(. This also includes the inverses such as , ³√(, ×√, and log( and ln(. These commands have a plethora of applications, one of them being the emulation of gravity.

Probability

This includes the commands of the random numbers as well as nPr, nCr, and !. These can be used to determine outcomes and allow for computer intelligence.

Trigonometry

These are some of the most powerful functions, including sin(, cos(, tan(, and their inverses. If these functions are used in the correct way, then you can create angles and simulate bouncing off of walls, off curved surfaces, and off angled surfaces. These functions can also be used to calculate physics solutions to the transfer of momentum, friction, and rates.

Complex Numbers

This is probably one of the hardest types of math to use. Complex numbers have both a real and an imaginary (i) part, where i=√(-1). Using these is challenging, but also very useful. You can use imaginary operations to find coordinate locations and store other parts of information.


This chapter will discuss the advanced uses of these math functions. You should already know how to use some of the above to perform various calculations, but the content of this chapter will be about how the operations can be used to perform calculations beyond what you can imagine. Another thing to consider is the use of these functions. Programs don't have to be all games, but you can create a various amount math routines.

<< Sample Program:Pong Table of Contents Operators >>
Nov 16 graphmastur does not match any existing user name just added the invisible include. Just use the "text" to supply the text to make invisible

{$text}

Optimizing logic is more of a speed issue than a size issue. Logic takes time for the calculator to interpret and thus requires optimization to be fast.

Because the calculator treats every nonzero value as true and zero as false, you don't need a comparison if a variable's value is nonzero. Instead, you can just put the variable by itself.

:If C≠0
can be
:If C

Instead of comparing a variable to zero, use the not( logical operator. Because not( returns the opposite value of the variable, true will become false and false will become true.
:While A=0
can be
:While not(A

When making expressions that combine the and and or operators where the and operator comes first, you don't need to include parentheses around the and operator. The and operator has a higher precedence than or, so it is evaluated first. This can become complicated with complex expressions, so you might want to leave some of the parentheses for clarity.
:If (A=1 and B=2) or (A=2 and B=1)
can be
:If A=1 and B=2 or A=2 and B=1

If you are comparing two unary expressions (expressions with no comparison operator) with the and operator, you don't need the and operator. For and to be true, both values must be nonzero. So, multiplying them will produce the same effect because if either one of the values is zero, the product of both values will also be zero.
:If A and B
can be
:If AB

A similar technique can be applied to expressions with comparison operators, except some restrictions are required.
With unary expressions, to test if A and B is true you multiply them. With equations, you can multiply the left sides of each together and you can do the same for the right sides. However, a value being 0 could return a different result than anticipated, so it is best to use this technique when the values are not 0. Also, this technique does not work when there are multiple values of A and C that multiply to get B times D. For instance, if A equals four, C equals 12, B equals six, and D equals eight, then this optimization will not work because A and B are not equal but A*C equals B*D.
:If A=B and C=D
can sometimes be
:If AC=BD

As and is similar to multiplying, the or operator is similar to addition. Adding two values together yields a non-zero result if one of the conditions is true. When you are comparing equations using the or operator, you can add the two together (This is usually not used for unary expressions because the plus and or symbols are both one-byte tokens). For this, the only restriction is that all values must have the same sign (or be 0), or you can circumvent this by using abs(. This is necessary because if two variables have the same value except one is negative, this expression could return false.
:If A=B or C=D
can sometimes be
:If A+C=B+D

The most unused logical operator is xor (exclusive or). The xor operator is useful when comparing two expressions and checking if one but not both are true. In fact, xor is specifically designed for this purpose.
:If A=2 and B≠2 or A≠2 and B=2
can be
:If A=2 xor B=2

Many times a compound expression can be shortened by combining expressions that have the same meaning or replacing expressions that can be written another way. Think about what the expression means and then think about how to make a shorter equivalent expression. There are many ways of writing an expression, so there are usually ways to rewrite it.
:If A>B or A<B
can be
:If A≠B

If you have the not( operator around an expression, you can usually change the logical operator to the math opposite. This allows you to remove the not( operator.
:If not(B=C and A=D
can be
:If B≠C or A≠D

DeMorgan's Law can be used for expressions in which the not( operator is around two separate unary expressions joined by the and or or operators. It allows you to remove the second not( operator and then change the and to or and vice versa.
:If not(A) and not(B
can be
:If not(A or B

Min( is useful when you are comparing one variable or value to several other variables to see if they are all equal to the variable or value. To use min you just create an expression with the min function and put the common variable or value inside it followed by an equal sign and a left curly brace. You then list out the variables that you are comparing the variable or value to, separating each one with a comma.
:If A=10 and B=10 and C=10
can be
:If min(10={A,B,C

Max( is useful when you are comparing one variable or value to several other variables to see if at least one is equal to the variable or value. You do the same thing as the min function, just replacing min with max.
:If A=10 or B=10 or C=10
can be
:If max(10={A,B,C

You can put a comparison operator inside the min or max functions to compare when several values or variables are equal to one variable and several values or variables are equal to another variable. This works especially well with three or more variables.
:If A=X and B=U or A=Y and B=V
can be
:If max(A={X,Y} and B={U,V

Abs( is useful when you are comparing a variable to two even or odd values using the or operator. You subtract the smaller value from the larger value, divide the result by two, and then put it on the left side of the equal sign. Next, you subtract the number on the left of the equal sign from the larger value, and then subtract that from the variable being tested inside the abs( command. Lastly, you place the resulting equation on the right of the equal sign.
In other words:
:If A=45 or A=105
can be
:If 30=abs(A-75

X=n1 or X=n2 should become abs(n1-mean({n1,n2}))=abs(X-mean({n1,n2})) (simplified) if n1 and n2 are positive integers and n1+n2 is even. If there are three terms, then see if you can simplify two of them according to this rule. If you can't, then a string of or's will be faster than the max(X={n1,n2,… approach. If there are four terms or more, then use max().
<< Math Operations Table of Contents Conditionals >>
Nov 12 The Creating Games section of the Starter Kit is now complete!

You should now know how to make some basic functional games. As a review for this chapter, here is a sample game that includes most of the things you have learned. The game is called Chase the Star. The goal of this game is to chase a randomly moving star until you catch it. The only trick is, the star doesn't erase its previous position making it a little more concealed.

The Program

:ClrHome
:2→A:2→B
:7→C:15→D
:Repeat (A=C and B=Ans) or K=21
:getKey→K
:If Ans
:Output(A,B,"_")
:A+sum(ΔList(Ans={25,34}))
:Ans-8(Ans=9)+8(not(Ans))→A
:B+sum(ΔList(K={24,26}))
:Ans-16(Ans=17)+16(not(Ans))→B
:C+randInt(-1,1)
:Ans-8(Ans=9)+8(not(Ans))→C
:D+randInt(-1,1)
:Ans-16(Ans=17)+16(not(Ans))→D
:Output(A,B,"X")
:Output(C,D,"*")
:End
:Pause "You_"+sub("Win!Lose",4(K=21)+1,4)
:ClrHome:"_"

An Explanation

:ClrHome
:2→A:2→B
:7→C:15→D

The first step is to set up the game. We use ClrHome to clear the home screen. The next thing we do is initialize the position of each object: the X and the *. The X, (A,B), starts at coordinate (2,2). The star, (C,D), starts at coordinate (7,15).
:Repeat (A=C and B=Ans) or K=21
:getKey→K
:If Ans
:Output(A,B,"_")

Now, we begin the game. Since this is an action game, a Repeat loop will be used. The game will end whenever the X coordinates and * coordinates match or the 2nd button is pressed. Next, the game will ask for input using getKey. This way, the program can recognize key presses to support movement. The next part checks to see if the user pressed anything. If the Ans is not 0 (the user pressed something), the X will be erased. That way, the program can redefine the X coordinates and then redraw X accordingly later on.
:A+sum(ΔList(Ans={25,34}))
:Ans-8(Ans=9)+8(not(Ans))→A
:B+sum(ΔList(K={24,26}))
:Ans-16(Ans=17)+16(not(Ans))→B

Here is a bit of a new code. This isn't the normal code that you would see in movement. The reason is this time, when the player moves off the screen, we want the X to be redrawn on the other side. To do this, we first find out what direction the user moved. This can be done with the normal code without min( and max(. Next, we will redefine A. If the Ans, which is the projected A, is 9, that means it is past the boundary. So, we subtract 8 to make it 1. If it is 0 (notice we used not(), then we add 8 to make it 8. The same is done with the B variable. The only difference is that since the far boundary for B is 16, we need to add or subtract that to make B normal.
:C+randInt(-1,1)
:Ans-8(Ans=9)+8(not(Ans))→C
:D+randInt(-1,1)
:Ans-16(Ans=17)+16(not(Ans))→D

The * does something very similar. Since its movement is random, we use randInt(. The -1 and 1 tells whether to move up or down. The next part is completely identical to the previous coding in order to make the * wrap to the other side.

Note that sometimes the * won't move at all. Since randInt( will select a number from -1 to 1, 0 is sometimes selected.

:Output(A,B,"X")
:Output(C,D,"*")
:End

The final part of the loop is the output. The X is redrawn at its new coordinates and the * is redrawn at its new coordinates. Note that the * doesn't erase its path! This is done intentionally for the game experience, but for other games, erasing the old copy might be an important step.
:Pause "You_"+sub("Win!Lose",4(K=21)+1,4)
:ClrHome:"_"

This is the final part of the program. What happens is the calculator uses the sub( command to determine whether to display "Win!" or "Lose". If the user pressed 2nd, then the program will display "Lose". If the user did not press second (meaning that the user must have caught the star), then the "Win!" message will be displayed. Then lastly, the program will reset the home screen as if nothing ever happened.

This concludes the chapter on making games. However, your journey is not yet complete. The next step is figuring out how to use the graph scene to make superior graphics. Have fun, and prepare to learn how to create some hardcore designs!

<< Exercises Table of Contents Introduction to the Graphscreen >>

Review

  1. What command will automatically unarchive a list and create it if it doesn't exist?
  2. What data type would you use to save a highscore?
  3. What is the seed and what is it useful for?
  4. What type of loop is appropriate to use for a game like Yahtzee?
  5. What is the code for movement?
  6. How can you modify the movement code in order to make it so that when you go off the screen, you loop to the other side?
  7. Can you use the sub( command to find the element in a matrix?
  8. Make a formula using rand as the only random command to yield the same results as randBin( with a given seed of 0.
  9. What happens when you take the inverse of a matrix with determinant 0?

Programming

Modify the following movement code that is supposed to move two objects simultaneously according to user input.

:1→A
:1→B
:4→C
:4→D
:Repeat K=21
:getKey→K
:If Ans
:Output(A,B,"_")
:min(8,max(1,A+sum(ΔList(Ans={25,34}))))→A
:min(16,max(1,B+sum(ΔList(K={24,26}))))→B
:Output(A,B,"X")
:End

Explain the usage for this code.
:rand→A
:A→rand

Create a game where the player must make it through a maze when the arrow key movements are jumbled up.
<< Summary Table of Contents Sample Program: Chase the Star >>

Here is a basic summary of what you have learned from this chapter.

  • The home screen has more than one form of output.
  • The getKey command can be used to recognize a key press.
  • Movement can be accomplished through the teamwork of getKey and ΔList(.
  • Games use skeleton loop to accomplish its main functions.
  • There are three special data types, matrices, lists, and strings, that can be used for special purposes, like map underlying, saving, and storing phrases.
  • You can use random numbers to enhance game play.

Commands Introduced

<< Random Numbers Table of Contents Exercises >>
Nov 11 James Kanjo upgraded the date structure of the news and members sections of the site. Now the date format can easily be modified via the date include page!
Apr 02 DarkerLine and James Kanjo worked together to upgrade the implemented "include template" sections of the site. Result: Site automatically retrieves the required parts of the "Did You Know" and "Featured Article" sections for the 83 68k home pages.
{$month} {$day} {$description}

author: 'MasterDonut09(Tanner Hollis)'
description: 'Battle against the computer with lasers across a field. Aim right against the unpredictable AI, or you might just get fried…'
arcade: '1'
graphics: '0'
platform: '0'
puzzle: '0'
rpg: '0'
strategy: '0'
sports: '0'
casino: '0'
board: '0'
utility: '0'
misc: '0'
image: /home/no_image_2.png
download: Battle.zip
size: '579'
unit: '1'

toolbar-separator.png This article is currently in development. You can help TI-Basic Developer by expanding it. Add more pertaining to division, exponentiation, and negation/subtraction

Optimizing math operations is a great way to make your programs more understandable and faster.

Simple Things

When optimizing any code in TI-Basic, you should check to see if your math is done efficiently. For instance, think of a situation where you need to multiply A by 7 and B by 4 and then multiply A and B. Remembering that multiplication doesn't care about order, wouldn't it be easier to just multiply 28 by A and multiply that by B? Here is is how that would look.

:7*A*4*B

works better as
:28*A*B

Now, remember that when you multiply variables with numbers on a calculator, it implies the multiplication. The same is true when multiplying variables together, but you have to do the multiplication yourself between two real numbers. This is what the previous code would look like with implied multiplication.
:28AB

As stated before, an important part of optimization is combining real numbers in your code.. Whenever you see two lone real numbers, combine them. For instance, don't ever write a program with A+1+3+5 in it. Write A+9, and save us some space.
Also, when you have an equation like 9*(X+3), it is better to distribute the nine than to leave the equation factored, because it saves the calculator a multiplication step which helps speed and size. This is something that should be done as a speed optimization when 9 is replaced with a one, two, or three digit number, and as a size optimization when 9 is replaced with a one or two digit number.
Another simple optimization trick is instead of multiplying by, say, 1000, just use E3 (the 'E' when [2nd][,] is pressed) Or use 10^x token under [2nd][LOG].

Complex Math Optimizing

Remember Polynomials? I know you do. Imagine the polynomial p(X)=(X+1)(2X+3), which takes 11 characters to write. I know you're wondering "why on earth are we talking about polynomials? I hate those!" But optimizing them when used is an important step. Notice that when expanded, p(X)=2X2+5X+3 is only 8 bytes, instead of 11. Because expanding a polynomial removes the implied multiplictation necessary for the calculator to do previously, it not only is better size-wise but improves the speed of your program.

<< Optimizing Variables Table of Contents Logic Operations >>

The Graph Screen is 95 pixels wide and 63 pixels high. As can be seen from the Draw Menu there are a variety of ways to display graphics. Manipulating points and pixels is one of the simplest yet most effective ways to get all you can out of the Graph Screen.

Note: Unless otherwise stated the window settings are Xmin=0, Xmax=94, Ymin=-62, and Ymax=0.

ClrDraw

The first thing you need to know when you deal with the Graph Screen is how to erase your draw. The function you need is ClrDraw. It's found in the Draw Menu and has no syntax. Simply enter ClrDraw as above and the Graph Screen will erase.

:RecallPic1
:Pause
:ClrDraw

This code will recall Pic1 then wait for the user to press Enter and finally erase all it's content. Now, let's draw !

Pixels

The graph screen is 95 pixels wide and 63 pixels high. Similar to Output( on the Home Screen, the first argument of any Pxl- command is the y-coordinate. This starts at 0 from the top (not at 1) and increases as you move down to the bottom row numbered 62. The second argument is the x-coordinate, starting at 0 on the left and increasing to 94 at the right of the screen.

Two advantages using Pxl- commands has over Pt- commands are the coordinates and speed. The coordinates always range from 0-94 and 0-62 so you don't have to worry about the user's window settings. Turning pixels on/off takes almost 2/3 the time it takes their Pt- counterparts.

Pxl-On(

The Pxl-On( command is used to turn a pixel on. It only takes two arguments which are the row and the column. This is useful when you need just a little tweak for the perfect graphic.
Here's an example. Let's say you want to draw a face. You could use Circle( (we'll get to that later) for the head but then you're missing the eyes. Turn a couple pixels on!

:Circle(47,-31,4)
:Pxl-On(30,46)
:Pxl-On(30,48)

Pxl-Off(

Pxl-Off( is used to turn a pixel off. It's arguments are the same as Pxl-On. This is useful when you need to get rid of a couple little things. For example, if we wanted to add a mouth on our little head we could use Pt-On (which is coming right after this) and its special 'mark' argument and then turn off the 2 pixels we don't need.

:Pt-On(47,-32,3)
:Pxl-Off(31,47)
:Pxl-Off(33,47)

Pxl-Change(

Pxl-Change( swaps the current state of a pixel. The arguments are identical to those used with Pxl-On and Pxl-Off. A great use for this is in animations where you have something moving through an object. Here is an example. For most shooting games you don't want to interfere with the background, but if you just turn a pixel on then turn it off after it leaves, you could have a big gaping hole where there shouldn't be!
The top image uses Pxl-Change( and the bottom uses Pxl-On/Pxl-Off.
pxlChangeScreenshot

The code for the bullet(s) is

:For(A,46,94)
:Pxl-Change(16,A)
:Pxl-Change(16,A-1) \\Top part
:Pxl-On(36,A)
:Pxl-Off(36,A-1) \\Bottom part
:End

There is very little difference between the code for each but there are major differences between the outputs!.

Pxl-Test(

pxl-Test( checks to see if a pixel is on or off. It's two arguments are the same as the other pixel commands but instead of drawing/un-drawing something it returns a 1 if that pixel is on and a 0 if it is off. This is incredibly useful for collision detection. A common example of its use is in a game of snake/nibbles. If the new position of the head was already 'on', then that means it hit something it shouldn't have so they lose.

Points

In contrast with pixels, the coordinates used by Pt- commands depend on your current window settings. This could be a problem if you don't want to worry about the user's window settings. It can also be an advantage which allows you to simplify many arguments for drawing commands.

The first argument for Pt- commands is the x coordinate and the second is y, the reverse of modifying pixels. Keep in mind that for the y-coordinate it increases as you move upwards just like a normal graph.
The third argument, unique to points, is the 'mark'. The number 1 corresponds to a regular one-pixel point. Two is a box with the center missing. Three corresponds to a little '+'.

Pt-On(

Pt-On( draws the 'mark' at the indicated point. The extra 'mark' argument allows you to make more complicated graphics without drawing them pixel-by-pixel. Below shows how the different marks can be used for a snake/nibbles game.
snakeScreenshot

Pt-Off(

Pt-Off( erases the mark at a point. This doesn't just turn off the pixel at the point, but it turns off every pixel that would be part of the mark. An example of using these to get a cool-looking point is

:Pt-On(20,-20,2)
:Pt-Off(20,-20,3)

This will only leave the corner pixels of the little box.

Pt-Change(

Pt-Change( switches the state of the point. Unlike the other two point commands there is not 'mark' argument making this essentially Pxl-Change( except for the coordinates used.


Points and Pixels on TI 84+CSE and TI 84+CE Version Calculators

For those of you who have a TI 84+C version (i.e. one that is capable of displaying color), then the drawing systems are slightly altered. However, the color functionality and higher screen resolution allows for more detailed and colorful graphics!

Note: When working with colors in commands, if no color argument is given, then the pixel or point will automatically be BLUE.

Screen Dimensions

On TI 84+C version calculators, the dimensions of the screen are 165 pixels high and 265 pixels wide. This is a MUCH higher resolution than the monochrome counterparts, allowing for very detailed graphics and sprites. Like other versions, the first pixel (0,0) is in the top left corner and the last pixel (164,264) is in the bottom right.

The Pxl-On, Pxl-Off, and Pxl-Change commands still work the same, but with the new dimensions. Points are unaffected by the screen change, as they are still dependent on the graph screen.

Working with Colored Pixels

If you have a TI 84+C version calculator, you are probably anxious to use its biggest upgrade: color! Color is only available on the graph screen (unfortunately, color text cannot be displayed on the home screen), and can be used with both pixels and points.

Let's start with pixel commands. To draw a colored pixel, simply add a color name to end of the Pxl-On( command, as shown below.

:ClrDraw
:Pxl-On(82,132,RED //Draws a red pixel near at the center of the screen
:Pxl-Off(82,132 //Turns off pixels regardless of pixel color

Notice that the pixel is much smaller than on the grayscale calculators. This allows for more detail, but this also means it takes more commands to draw simpler designs.

You can also call a pixel's color using the color ID, which ranges from 10 to 24. The ID can be stored in a variable, making it very useful for to change colors in a For( loop. The code below will draw a pixel at the (A,B) and loop through all the possible colors in the order they appear in the VARS list.

:ClrDraw
:Lbl 1
:For(X,10,24
:Pxl-On(A,B,X
:End
:Goto 1

Note that in the code above you must press [ON] in order to exit. You can change the loop to a Repeat loop with a conditional if you want to use it in a game or other program.

The Pxl-Change( command can be used in a similar fashion as Pxl-On(, changing the pixel from on (color does not matter) to off or from off to a desired color, as shown below. If the pixel is already on, then it will be turned off, even if a color argument is given.

:ClrDraw
:Pxl-Change(82,132,YELLOW

The Pxl-Test( command works the same as it does on the monochrome calculators, but there is one catch: Pxl-Test( cannot be used to test for the color of a pixel, just whether it is on or off. Though this is an annoying handicap, Pxl-Test( is still just as useful for boundary detection, except now it can detect pixels of any color.

Working with Colored Points

Now let's look at coloring points. Like on monochrome calculators, points are denoted the same way on the graph screen, using (X,Y) coordinates. The points, when drawn, cover more pixels than on grayscale calculators, but are still the same size relative to the graph screen. This makes point commands much more effective when drawing multiple pixels.

The Pt-On( command now takes a fourth argument for color to draw. The mark argument, as well as the color argument, are still optional, but can also now be interchanged in order. This means that you can draw a colored point of default mark without having to put an extra "1" to signify a default argument. Here is an example:

:ClrDraw
:Pt-On(0,0,1,GREEN
is the same as
:Pt-On(0,0,GREEN //The calculator will recognize no mark is given and draw the default point
:Pt-Off(0,0 //Turns off the point regardless of color

The Pt-Change( command, like the Pxl-Change( command, still changes the on or off status of a point, but now takes a color argument when turning points on. The point will still be turned off if it already on, even if a color argument is given:

:ClrDraw
:Pt-Change(0,0,ORANGE

Just like with monochrome calculators, there is still no mark argument for Pt-Change(.

<< Introduction to the Graphscreen Table of Contents Graph Format Settings >>
toolbar-separator.png This article is currently in development. You can help TI-Basic Developer by expanding it.

In the starter kit, the link to this page has been re-linked to a more thorough, non-starter kit page concerning variable optimization. This page may be deleted.

<< Displaying Text Table of Contents Math Operations >>

Optimizing text is one of the best ways to optimize your program. It is easy, and it shaves off many bytes.

Homescreen Specific Optimizations

The following optimizations are only useful for users of the homescreen.

Using Disp Instead of Output(

when you display a short quote at (1,1) on the homescreen, try to use Disp instead of Output. This change does not affect displayed information at all and merely shortens the code a little.

Using Output( to Wrap Text

Because the output command wraps text, Paragraphs are much better displayed on the homescreen using one Output command than using eight or so Disp commands. This optimization can be used to improve size for any display on the homescreen where characters are within seven spaces from each other. Here is an example that would be used as a title screen layout.

:Output(3,2,"ULTIMATE QUEST
:Output(4,3,"DEVELOPED BY
:Output(5,4,"YOUR NAME

is shortened by putting
:Output(3,2,"ULTIMATE QUEST //three spaces// DEVELOPED BY //five spaces// YOUR NAME

this optimization saves an average of three bytes per line.

Graphscreen Optimization

On the graphscreen alone, you can have text and variables displayed on the same line with the same text( command. Separate them with commas. This eliminates the need for the 1+int(log( trick.

:Text(1,1,"HP=
:Text(1,13,H
:4int(log(H
:Text(1,17+Ans,"/
:Text(1,21+Ans,P

can be greatly reduced to
:Text(1,1,"HP=",H,"/",P

Optimizations for Both Screens

The following optimizations can be applied to both the homescreen and the graphscreen to improve size.

The Pause Optional Argument

When you have a list of Disp commands that you pause, you can take the text or variable from the last Disp command and place it after the Pause command as its optional argument, allowing you to remove the last Disp command.

:Disp "A=
:Disp A
:Pause
can be
:Disp "A=
:Pause A

Shortening Conditionals

When you have two or more Disp statements inside an If-Then conditional, you should combine the Disp statements so you can change the If-Then conditional to an If conditional.

:If A>B
:Then
:Disp "A is greater
:Disp "than B
:End

can be
:If A>B
:Disp "A is greater","than B

Shortening Text Length

The first things to do when optimizing text include removing the end parenthesis and quotation marks, as we've already explained. Other things that you can do to optimize include replacing certain words with shorter synonyms and removing embellishing words. Here is an example.

:Output(1,1,"YOU HAVE BEATEN")
:Output(2,1,"THE GAME!")

can be much reduced to
:Output(1,1,"YOU WON!

By removing the excess words and changing beat to won. This optimization saved 27 bytes. Now think of having an unoptimized text adventure, with over one hundred individual text display commands. You could save 2700 bytes just by optimizing the text in that game! Now do you see why optimizing text is so important?

Using sub( to Reduce Size

If someone wins your game, don't you want to tell them that they won with a couple really optimized commands like these? (Pretend that the user has exited the game loop, he has either won or lost, and if A=10 then he won)

:If A=10
:Then
:Output(4,5,"YOU WIN
:Else
:Output(4,5,"YOU LOST
:End

But have you ever thought of using the sub( command to combine the two times the word YOU is displayed? Consider the following code, which is six bytes smaller.
:Output(4,5,"YOU"+sub("WON LOST",1+4(A≠10),4

This code works because in the case that A=10 it should start at 1 at remove four characters and in any other case it should start at 5 and remove four characters.

Deleting repeat phrases

If a word or phrase is repeated, you can reduce size by eliminating it and the display commands, and adding the repeat phrase to a string stored in ans. Note that in this case, it is smaller to use sub( than to do this.

:If A=10
:Then
:Output(4,5,"YOU WIN
:Else
:Output(4,5,"YOU LOSE
:End

can be improved to
:"LOSE
:If A=10
:"WIN
:Output(4,5,"YOU"+Ans

Conclusion

As you have seen, optimizing text is an important thing to do when finishing up your programs, and if you stick to it, your text based programs can be much improved.

<< What is Optimization Table of Contents Optimizing Variables >>

Simply put, optimization is making your game better. It involves reviewing all of your code and looking for subtle changes that can be made, that as a whole, decrease the size of your program and speed it up.

Simple optimizations

There are many ways you can optimize a program. This is a common optimization.

:Output(1,1,A-(B-C))

can be optimized to
:Output(1,1,A-B+C

because subtracting a negative is the same as adding a positive, and because parentheses are not needed at the end of any Output( command or other command where the last token on the line is the parentheses. Another common optimization is quotation marks, which also can be omitted from the end of the Output command. For an example, see the following.
:Output(1,1,"HELLO WORLD")

can be
:Output(1,1,"HELLO WORLD

Complex optimizations

Optimizing isn't always easy. Sometimes, to make programs smaller, one has to scrap previously written code and completely rewrite the program with a different approach. This would be like saying "hey, my program is getting pretty big. I wonder what would happen if I used lists instead of matrices for my saved games?" and then writing the game using lists instead of matrices. This is known as algorithmic optimization, but that's a bit too in depth for a beginner class. If you do wish to know more about it, you can see it here.

Don't be worried. Optimizing is usually a fun process, and as you watch that byte count dwindle, you'll see what we're talking about.

<< Sample Program: Analog Clock Table of Contents Displaying Text >>
Nov 09 Program challenge #5 is finally over, now we begin challenge #6, the GUI challenge.
Nov 09 Congratulations to Timothy Foster for winning challenge #5 and entering the Hall of Fame!

If you remember the old movie, Tron, you might remember the premise of this game. You control a cycle (or in this case, a pixel) that moves in a direction until you change the direction. It leaves a path, and if you hit the path, or the wall, you lose. The trick here is that you must out last your opponent: an AI. This version of Light Cycles for the calculator utilizes a simple AI system that makes it kind of intelligent. Please try to understand the code and learn from it.

The Code

:Full
:FnOff
:AxesOff
:0→Xmin:1→ΔX
:0→Ymin:1→ΔY
:ClrDraw
:Vertical Xmin
:Vertical Xmax
:Horizontal Ymin
:Horizontal Ymax
:60→A:92→B
:2→C:2→D:25→G
:Pxl-On(A,B
:Pxl-On(C,D
:Text(-1,28,31,"READY?
:Pause
:For(E,26,36
:Line(29,E,67,E,0
:End
:Repeat G=45 or not(pxl-Test(A,B) and pxl-Test(C,D
:getKey
:If Ans
:Ans→G
:A+(G=34)-(G=25→A
:B+(G=26)-(G=24→B
:1+pxl-Test(C+1,D
:Ans+(Ans=2 and pxl-Test(C,D-1
:Ans+(Ans=3 and pxl-Test(C-1,D→F
:C+(Ans=1)-(Ans=3→C
:D+(F=4)-(F=2→D
:Pxl-Change(A,B
:Pxl-Change(C,D
:End

This is a tutorial on how to upload files onto the TI-Basic Developer. It has been requested that a step-by-step guide be created, as the process can be quite complicated to new contributors.

I am going to create a picture file to be uploaded…

Screenshot_01.PNG

Now I need to save it. Click "File", then "Save As…"

Screenshot_02.PNG

This next step may seem quite obvious. I feel though, that it is necessary to show everybody how to save in a *.PNG format. Click on the "Save as type:" drop-down box, and select "PNG (*.PNG)".

Screenshot_03.PNG

The PNG format is a superior one, as it is a lossless format (retains the full quality of the image), it is compressed (the file size is much smaller than a raw image) and it supports transparency (you can have "see-through" backgrounds).

I have saved my image on the desktop:

Screenshot_04.PNG

The next step is to open up your favourite web-browser, and navigate to the page you want to upload your file on. In my case, it's the 83 home page:

Screenshot_05.PNG

Scroll to the bottom of the page, and in the bottom-right hand corner is a selection of buttons. If you can't see these buttons, you may not be logged in (log in by pressing the "log in" link at the very top-right hand corner of the page). Now click on the "files" button (which conveniently appears in red in this image):

Screenshot_06.PNG

A menu appears just below the buttons. Click on the "upload new file" link, which has also conveniently appeared in red for some reason:

Screenshot_07.PNG

Another menu appears below. Now click the "Choose File" button:

Screenshot_08.PNG

Just navigate to where you saved your file — mine was saved on the desktop. Then click on the file, and click on the "Open" button:

Screenshot_09.PNG

Notice how your file appears in the "File to upload:" text box. When uploading files on the internet, it is always wise to make the file-name all one word, and all lowercase. We are going to do that now:

Screenshot_10.PNG

You MUST remember to add the last four characters to the new file name. In this case, we added .png. If you don't it will cause problems later.

Now click on the "upload file" button:

Screenshot_11.PNG

Hooray! Your file is now uploaded to the TI-Basic Developer! You will notice the list of files (arranged automatically in alphabetical order) now contains your file. Click on the "info" link:

Screenshot_12.PNG

Now comes up a box, including the URL of the file. The URL is important because it means you can access the file simply by clicking (or typing in) the address.

Screenshot_13.PNG

Name: Quarterback Rating
Author: patriotsfan
Download: qbrating.zip
Compatibility: Parent page not set
File Size: 975 bytes
This program calculates quarterback ratings for four different leagues: NFL, CFL, NCAA, and AFL.
Name: Boggle
Author: patriotsfan
Download: Boggle.zip
Compatibility: Parent page not set
File Size: 2277 bytes
This game is based on the original Boggle game. It is easy to use, and provides hours of entertainment for avid Boggle players! Definitely worth a download!
Nov 07 A new convention has been added to the Code of Conduct pertaining to the rating of programs.
Name: Line Judge
Author: MasterDonut09 (Tanner Hollis)
Download: LINJUDG.zip
Compatibility: Parent page not set
File Size: 842 Bytes
The object is to get your line across this maze of dots. Get lucky and you win. You lose, restart!
if you are bored, good game, if you are not bored, then its a decent game.

Now that you have learned about the skeleton of a game, the next part is the meat. A game can only run if variables are used. By now, you should know what a variable is, like A and B and X and so on. However, there are some other specialized variables also available on the calculator. These special data types can be used for superior game design and are used for effect and output. In the next three sections of this chapter, you will learn about these three variable types and their functions.

Storing & Deleting Variables

Variables have values stored in them so that the values can be recalled for later use. When storing an expression containing a variable into another variable, the value of the variable at that time is used. The store (→) command is used for storing variables, and it is accessed by pressing the [STO►] key. When storing a value in a variable, you have the value on the left side of the store command and the variable that it will be stored to on the right side.

:value→variable

When you are done using variables, you can delete them with the DelVar command to save space. This is especially important for lists, matrices, and pictures — since they take up the most space. The DelVar command deletes the contents of a variable from memory. If the DelVar command is used with a real variable, the variable is not only deleted from memory but automatically set to zero the next time it is used. DelVar does not work on specific elements of a list or matrix. In fact, it will actually return an error.

:DelVar variable

Numeric variables

Numeric variables are used for storing numbers. There are 27 numeric variables (from A to Z and θ) that can be easily accessed, and more that the calculator uses for its specific purposes.

Most numeric variables can either be real or complex (the latter involve i, the square root of -1, and are important to advanced algebra). In either case, up to 14 digits of a number can be stored, although only the first 10 will be displayed and used for comparison.

To access a real variable, press ALPHA and then the key corresponding to whatever letter you want your variable to be. You can initialize a real variable by storing a number, another variable, or an expression into the variable using the STO key (or, just using it almost anywhere will initialize it to 0).

List Variables

Lists are used to hold multiple numbers at once, in a specific order. There are six "default" lists named L1 through L6, but an important feature of lists is that they can be given names, so that there are millions of possible lists. Lists are important for programmers for many purposes - saving data after a program finishes running, and storing a level of a game are only two of them.

Matrix Variables

Matrices are two-dimensional lists (row by column). Equivalent to lists, they are used when the data needs more structure. Matrices are often used for storing a level or a map of the screen. There are only ten matrices available (from [A] to [J]).

String Variables

Strings are used for storing a sequence of characters, that is, text. A common use for strings is to manipulate text to be displayed in a program, but they have many different purposes: highscores, level and map data, and whatever else is desired. Although there are only ten built-in string variables (Str0 through Str9) available to use, strings can hold many different kinds of characters, including letters (both uppercase and lowercase), numbers, functions, and even other commands. The amount of free RAM is the only limit on the number of characters in a string.

Picture Variables and GDBs

Picture variables and GDBs (short for Graph DataBase) are used to save two different elements of the current graph display. A picture variable is used to store the exact appearance of the graph screen. A GDB is used to store system variables relevant to the graph screen - equations, window settings, and the like. 10 built-in variables of each type exist: Pic0 through Pic9 for pictures and GDB0 through GDB9 for GDBs.

(for more information, see Pictures and GDBs)

System Variables

System variables are, for the purposes of this guide, variables that certain commands will use or modify without asking (i.e. without supplying them in the command's arguments). This is a somewhat ill-defined category, and in fact the system variables we'll discuss are of a somewhat miscellaneous nature. They include equation and plot variables, window and table parameters, statistical variables, and finance variables.

(for more information, see System Variables)

Converting Between Variable Types

Between lists and matrices

The List►matr( and Matr►list( commands are used to convert between a matrix and several lists. Using these commands, it should be simple to implement any kind of conversion between these two data types.

Between strings and numbers

It is very easy to convert a string version of an expression to a number, list, or matrix: the expr( command can do it — for example, expr("5") will give you the number 5, and expr("{1,2,3}") will give you the list {1 2 3}.

Going the other way, however, is slightly more complicated because there is no built-in command to do it. What you need to use instead are a few small routines: see number to string for how to convert a number to a string. To convert a list or matrix, convert each individual element instead.

Archiving and Unarchiving Variables

On the TI-83+/84+/SE calculators, you can archive and unarchive variables. What this entails is the calculator moving the variable to the archive memory or the calculator moving the variable to RAM respectively. The main advantage of archiving a variable is that it is protected from calculator crashes, which clear the calculator's RAM. At the same time, you can't access a variable that's archived; it needs to be in RAM to use it.

:Archive L1
:UnArchive Str1

There are a couple things you need to be aware of when using Archive and UnArchive. First, since the TI-83 only has RAM, archiving is not possible, and subsequently neither of these commands are available. This means that you shouldn't use either of these commands if you plan on porting a program to the TI-83. Second, archiving does not work with the majority of the system variables, including the graphing, statistical, and finance variables. You can archive the other types of variables, however, although list variables are actually more manageable using the SetUpEditor command.

<< The Game Loop Table of Contents Data Types (Lists) >>

Movement is commonly used in programs as a way to add user interaction. It is part of user input as it relies exclusively upon the getKey command to work. You can use movement in many programs and for many different things, including moving a cursor in a menu or moving a character around the screen. It is the latter case that we are going to explain and show here.

The Code

To achieve the function of movement, we need to use some intense code and combine that with the attribute of getKey. First of all, the object that is being moved must have an identification. In two-dimensional space, the object needs two numbers to represent its position: the x coordinate, and the y coordinate. Those can be represented by a couple of real variables, for example, A and B. The next key for movement is to change the object's position. This can be done by adding or subtracting 1 to A or B, which will inevitably change the object's position. The next thing is outputting the result.

Home Screen

On the home screen, movement is quite easy. The x-axis uses numbers 1-16, and the y axis uses numbers 1-8. We'll provide a simple description of the code here. First, we must identify the position of the object. Our object is an X, and we want it to be at the center of the screen. So, it needs to be at the coordinates (8,4). However, remember that the position on the home screen is inverted to (y,x), so the actual coordinates are (4,8). We want to store these coordinates. Ok, easy enough…

:4→A
:8→B

Next, we need to make a loop so that the user can move the object multiple times. We will use a Repeat loop so that the code will repeat until the condition is met.
:Repeat K=21

Now, we need to retrieve input from the user. We need to use getKey to identify which arrow key was pressed. So, we will simply install the command and store it into K. Note that we could also use other keys for movement in place of the arrows (like the number pad for using 8 directions), but the arrow keys are simplest here.
:getKey→K

Now, we need to make sure that the user pressed a key. We don't want to erase the object's current position on every loop, so we use a conditional to make sure the key is pressed. Otherwise, the object blinks repeatedly.
:If Ans

The next step is to output the space. If a key is pressed, we need to erase the X so that when we output its new position, the object isn't duplicated. To erase something on the home screen, we simply output a space.
:Output(A,B," ")

The next part is one of the more confusing things we'll be teaching you in this guide, so listen closely. We'll need to look at the code in reverse to analyze it. Here is what it looks like:
:min(8,max(1,A+sum(ΔList(Ans={25,34→A
:min(16,max(1,B+sum(ΔList(K={24,26→B

A quick and dirty explanation. We know K is the value of a keypress. The point is to test which key exactly was pressed. We compare the variable K to a list containing the left and right key values. If left was pressed, the list becomes {1,0}. If right was pressed, the list becomes {0,1}. If neither, {0,0}. Next is the ΔList( command. That command will calculate the difference between the second and first elements in the list. So, if the list was {1,0}, then ΔList({1,0}) becomes {-1}. ΔList({0,1}) is {1}, and ΔList({0,0}) is {0}. sum( is used to convert the list into a real number that can be added to B. So, if the input was left, the operation becomes B+(-1). Next up are the max( and min( commands. The max( and min( commands are used to create a boundary for the object so that it does not fly off the screen, causing an error in the program. max( compares 1 and the new value of B to make sure it is not too far to the left. If it is, B is reset to 1. The min( command compares the new value of B to 16 to make sure the object doesn't fly off to the right. If it is, B automatically becomes 16. This is done with both A and B, adjusting for the different boundaries and getKey values associated with the horiontal and vertical planes.

Finally, we need to output X at its new position. Simply use the Output( command, and end the loop.

:Output(A,Ans,"X")
:End

(Note!: Ans is used because it is faster than using B. Because we just calculated the value of B, its contents are already stored in Ans!)

Putting all this together, we can now create out program!

PROGRAM:MOVE
:4→A
:8→B
:Repeat K=21
:getKey→K
:If Ans
:Output(A,B," ")
:min(8,max(1,A+sum(ΔList(Ans={25,34→A
:min(16,max(1,B+sum(ΔList(K={24,26→B
:Output(A,Ans,"X")
:End

That's how movement works! There are a few more things to consider though, and those are discussed below. Remember that you don't need end brackets on the end of a line or in special situations like before the store command. We use them here on the outputs to make it clearer that there is a space in the first one.

For an in depth explanation of the code, you can visit this page.

Simultaneous Movement

Movement is not limited to those two codes. The next step is to add enhancements to make the code work everywhere. For example, what if you have two things moving at the same time? What does that code look like? Unfortunately, the calculator can only output separate objects one at a time. True simultaneous movement is hard to accomplish. However, it can be simulated.

First of all, since you have multiple objects, you need multiple pairs of coordinates. The easiest way would be to use a bunch of real variables, but that isn't always the best way. For a small amount of objects, like from 2-3, real variables can be used. However, for large amounts of objects, like 4-10 or even more, a list might be needed because of the limited amount of reals. Now, another thing to consider is speed. The more objects moving, the slower the program will be. Make sure you define what you are wanting before writing a code.

Now, let's say you only want two things moving at a time. You want the calculator to randomly move an X and an O. First, you need to initialize their positions. The X will start at the top left corner and the O will start at the bottom right. Since we are moving only two objects, we can use real variables. A and B will be X, and C and D will be O.

:1→A
:1→B
:8→C
:16→D

The next step is to start the loop. The loop ends when the objects collide or a button is pressed.
:Repeat getKey or (A=C and B=D)

Now, since the two objects are just moving randomly, you don't need to ask for input. Thus, no little getKey command is needed to determine movement. So, the next step is to simply erase the current positions of the objects since we know they are going to move anyway. Just output a space for each coordinate, remembering the form (x,y).
:Output(A,B,"_")
:Output(C,D,"_")

Now, the coordinates have to be redefined to represent movement. Since the movement is random, we will use randInt(. (You will learn random commands later). We can create a variant of the code used for normal movement, but since we don't need to test a getKey, we don't need ΔList( or anything. However, min( and max( are still needed to test the boundaries. So, here is the code.
:min(8,max(1,A+randInt(-1,1)))→A
:min(16,max(1,B+randInt(-1,1)))→B
:min(8,max(1,C+randInt(-1,1)))→C
:min(16,max(1,D+randInt(-1,1)))→D

The final part is the output. Simply output each character with the new values.
:Output(A,B,"X")
:Output(C,D,"O")
:End

Putting the code together, we get the following:
PROGRAM:MOVE3
:1→A
:1→B
:8→C
:16→D
:Repeat getKey or (A=C and B=D)
:Output(A,B,"_")
:Output(C,D,"_")
:min(8,max(1,A+randInt(-1,1)))→A
:min(16,max(1,B+randInt(-1,1)))→B
:min(8,max(1,C+randInt(-1,1)))→C
:min(16,max(1,D+randInt(-1,1)))→D
:Output(A,B,"X")
:Output(C,D,"O")
:End

So, now you can create movement emulations for user interaction and create calculator generated motion along with simultaneous elements.

Unfortunately, when trying to move 5 or more objects, real variables become a hassle. When you juggle a ton of objects, you must use a list to keep track of all the coordinates and to make a speedy program. You won't need to know this now though, for as you progress with further lessons, you will gradually gain that knowledge.

Collision detection

The next step is pertains to this question: How can I create walls where the object can't go through them? With the previous codes, if you create a random boundary, the object can still go through it. What if you want to make a maze? Well, fortunately, there is a way. To make boundaries, you have to add some sort of conditional testing for if there is a wall there or not. The way you do that is creating an underlying code that describes the board on which an object is located. There are many ways to do this.

Let's create a simple maze where you are guiding an X, and the walls are I's. What we must first do is initialize the maze in one of the data types (which you will learn later). The best way is to use a string; however the easiest way is by matrices. A matrix is a two dimensional array of information. What we need to do is use three numbers: 1 will be a wall, 0 will be a space, and 2 will be the end of the maze. Store the maze into a matrix variable by inputting the whole code.

:[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  [1,0,0,0,1,1,0,0,1,1,1,0,0,0,1,1]
  [1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1]
  [1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,1]
  [1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1]
  [1,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1]
  [1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,1]
  [1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1]]→[A]

Notice that the dimensions of this code is 8 x 16, the exact dimensions of the home screen! This code will be "under" the home screen so that the calculator can sense a collision when asked to. Of course, you will still need some special code.

Next, you want to initialize the position of the object. We want it near the top left corner, i.e. (2,2).

:2→A
:2→B

Okay, now we need to do a few different things. You cannot jump into the movement phase just yet, because now the map needs to be shown. To display the map, we need to use a couple of For( loops to represent each element. The first represents the row while the second represents the column. The code then needs to use the sub( command to find which character, either I for a wall, a space for a 0, and a W for the winning space. It tests what the matrix element is and outputs that accordingly.
:For(C,1,8)
:For(D,1,16)
:Output(C,D,sub("_IW",[A](C,D)+1,1))
:End
:End

Now we will start the main movement loop. The first thing you need to do is define the loop with Repeat. This time, the conditional needs to test when the player reaches the W, or the matrix number 2. We can then define the loop like this.
:Repeat K=21 or [A](A,B)=2

The next natural step is to ask for input. Use getKey as usual.
:getKey→K

Next, test to see if there was a key press. If there was, clear the object for it to be redrawn later.
:If Ans
:Output(A,B,"_")

Now comes the movement code. It is a little more complicated now that we have to test whether or not the player has collided with a wall. Fortunately, since the surroundings are all walls, we won't need min( or max( to test the limits. We only need the code to test the walls. First, notice that the only way to reach the winning space is by going down. This will help on the code. Let's concentrate on vertical movement. Here is the code:
:sum(ΔList(Ans={25,34}))
:A+Ans([A](A+Ans,B)≠1)→A

Here is what we are doing. First, we need to find out whether we are going up or down. So, we are using the normal code for that. The next part tells us whether there is a wall in that direction or not. Consider the condition [A](A+Ans,B)≠1. This code is testing the square you want to move to. If the square is a winning space or normal space, the condition gives off 1. If the space is a wall, it says 0. Since this is being multiplied by Ans, the direction, the object will not change position if the condition is 0.

So, similarly, we can use that code for the lateral movement. The only difference is the conditional which is not([A](A,B+Ans)). We use not because you cannot reach the winning square with a horizontal key press. Thus, we do not need to test for 2 like before.

:sum(ΔList(K={24,26}))
:B+Ansnot([A](A,B+Ans))→B

Finally, we must output the result and close the loop.
:Output(A,Ans,"X")
:End

When we put all this code together, we get a functional maze program!
PROGRAM:MOVE4
:[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  [1,0,0,0,1,1,0,0,1,1,1,0,0,0,1,1]
  [1,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1]
  [1,0,1,1,0,0,1,1,0,1,0,0,1,1,0,1]
  [1,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1]
  [1,1,0,1,1,0,0,0,1,1,0,1,1,0,1,1]
  [1,1,0,0,0,0,1,1,1,0,0,1,1,0,0,1]
  [1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1]]→[A]
:2→A
:2→B
:For(C,1,8)
:For(D,1,16)
:Output(C,D,sub("_IW",[A](C,D)+1,1))
:End
:End
:Repeat K=21 or [A](A,B)=2
:getKey→K
:If Ans
:Output(A,B,"_")
:sum(ΔList(Ans={25,34}))
:A+Ans([A](A+Ans,B)≠1)→A
:sum(ΔList(K={24,26}))
:B+Ansnot([A](A,B+Ans))→B
:Output(A,Ans,"X")
:End

That sums up movement with collision. Remember, depending on the situation of the map, you might have to alter the code. That is the art of programming: it is not always consistent and needs constant intelligence from the programmer.

An Alternate Method

There is another way to display movement. It is faster, but it is also larger. This method is capable of absorbing conditionals very well which makes it a much more lenient code. Instead of using ΔList( and stuff, you can use a simple piecewise expression.

:A-(K=25 and A>1)+(K=34 and A<8)→A
:B-(K=24 and B>1)+(K=26 and B<16)→B

This code will also move something around the screen.

For collision detection, you could use

:A-(K=25 and [A](A-1,B)≠1)+(K=34 and not([A](A+1,B))→A
:B-(K=24 and not([A](A,B-1))+(K=26 and not([A](A,B+1))→B

See how easy it is just to add the extra condition? This code's flexibility makes it very popular, but remember that it should only be used when needed because of its size!

Full-screen on a TI-84+ CSE/CE

The TI-84+ CSE and CE models have a bigger screen size than previous models. Whereas the old dimensions were (for (Y,X)) (8,16), the new models are (10,26). The above programs are for the old dimensions, and while they will work on a 84+ CSE/CE, they don't display across the full screen. To change the programs MOVE and MOVE3, all you really have to do is change the Y and X maximums.

PROGRAM:MOVEC
:4→A
:8→B
:Repeat K=21
:getKey→K
:If Ans
:Output(A,B," ")
:min(10,max(1,A+sum(ΔList(Ans={25,34→A
:min(26,max(1,B+sum(ΔList(K={24,26→B
:Output(A,Ans,"X")
:End
PROGRAM:MOVE3C
:1→A
:1→B
:8→C
:16→D
:Repeat getKey or (A=C and B=D)
:Output(A,B,"_")
:Output(C,D,"_")
:min(10,max(1,A+randInt(-1,1)))→A
:min(26,max(1,B+randInt(-1,1)))→B
:min(10,max(1,C+randInt(-1,1)))→C
:min(26,max(1,D+randInt(-1,1)))→D
:Output(A,B,"X")
:Output(C,D,"O")
:End

Creating a full-screen maze is much more difficult, as it involves more than changing a few numbers. As opposed to making an 8x16 matrix, we have to make a 10x26 matrix, which obviously requires more work. Here is the code for a full-screen maze:

PROGRAM:MOVE4C
:[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
  [1,0,0,1,0,1,0,1,0,0,1,0,0,0,1,1,0,0,1,1,1,0,0,0,1,1]
  [1,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,1]
  [1,0,1,0,1,0,0,0,1,0,1,0,1,1,0,0,1,1,0,1,0,1,1,1,0,1]
  [1,0,1,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,1,0,1,1,0,0,1]
  [1,0,1,0,1,0,1,0,1,0,0,1,0,1,1,0,0,0,1,1,0,1,1,1,0,1]
  [1,0,1,0,1,0,1,0,1,0,1,1,0,1,0,0,1,1,1,1,0,1,1,0,0,1]
  [1,0,1,0,1,0,1,0,1,0,1,1,0,0,1,0,1,1,1,0,0,1,1,0,1,1]
  [1,0,0,0,1,0,1,0,1,0,1,1,1,0,0,0,1,1,1,0,1,1,1,0,0,1]
  [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1]]→[A]
:2→A
:2→B
:For(C,1,10)
:For(D,1,26)
:Output(C,D,sub("_IW",[A](C,D)+1,1))
:End
:End
:Repeat K=21 or [A](A,B)=2
:getKey→K
:If Ans
:Output(A,B,"_")
:sum(ΔList(Ans={25,34}))
:A+Ans([A](A+Ans,B)≠1)→A
:sum(ΔList(K={24,26}))
:B+Ansnot([A](A,B+Ans))→B
:Output(A,Ans,"X")
:End

Conclusion

Now that you know the core of movement, you now need to learn how to create the skeleton of all games: Loops. As you progress through the lessons, you will find better ways to make maps, emulate movement, and create better games. Have fun!

<< Using getKey Table of Contents The Game Loop >>

author: basickevin
description: 'A fully optimized, release ready full version of pong. Includes the ability to spin the ball and also to select a difficulty level, which speeds up the ball and makes the AI smarter on hard.'
arcade: '1'
graphics: '0'
platform: '0'
puzzle: '0'
rpg: '0'
strategy: '0'
sports: '0'
casino: '0'
board: '0'
utility: '0'
misc: '0'
image: '/archives:spin-pong/spinpong.gif'
download: Spin%20Pong.zip
size: '523'
unit: '1'

Routine Summary

Finds the remainder of a division between two numbers.

Inputs

A,M

Variables Used

A,M

Calculator Compatibility

TI-83/84/+/SE

:A-Mint(A/M

This program takes modular equations of the form X ≡ A (mod M) and solves them for the common residue, which is equal to the remainder after A has been divided by M. Among other things, it can be useful for finding the day of the week (with Sunday–Saturday matching up with 0–6) after M number of days has passed, or the time on a clock after a number of hours has passed.

For example, if we were on a Saturday (which is day 6, given that Sunday is day 0), and we wanted to figure out what it will be in 18 days, we would store 6+18→A, then 7→M as the appropriate number of days in a week, and finally we would calculate MfPart(A/M to get 3, which translates to a Wednesday.

This simpler version can be used if A is guaranteed to be positive:

:MfPart(A/M

It may fail due to rounding precision errors.
tags="+_challenge {$tags}"
Nov 03 thornahawk finished the invT( command. Now all calculator commands documented (again!)

Command Summary

Calculates the inverse of the cumulative Student's t-distribution function with degrees of freedom ν.

Command Syntax

invT(probability, ν)

Menu Location

Press:

  1. 2ND DISTR to access the distribution menu
  2. 4 to select invT(, or use arrows.

Calculator Compatibility

TI-84+/SE (OS 2.30 or greater)

Token Size

2 bytes

invT( is the inverse of the cumulative Student t distribution function: given a probability p and a specified degrees of freedom ν, it will return the number x such that tcdf(-E99,x,ν) is equal to p

:invT(.95,24
    1.710882023

Advanced

invT( is meant for use with so-called "one-tailed' tests; for two-tailed tests, the proper expression to use (corresponding to the inverse of tcdf(-x,x,ν)) is invT(.5(1+p),ν)

Formulas

Unlike the tpdf( and tcdf( commands, the invT( command does not have a closed-form formula. However, it can be expressed in terms of the inverse incomplete beta function.

For one degree of freedom, invT( is expressible in terms of simpler functions:

(1)
\begin{align} \definecolor{darkgreen}{rgb}{0.90,0.91,0.859}\pagecolor{darkgreen} \operatorname{invT}(p,1)=\tan\left(\pi\left(p-\frac1{2}\right)\right) \end{align}

Related Commands

Nov 02 Just noticed there is only one command that needs to be completed: invT(
Name: Minesweeper v3.1
Author: Timothy Foster
Download: Minesweeper1.1.zip
Compatibility: Parent page not set
File Size: 2530 bytes

This is minesweeper written in pure BASIC, no assembly. It takes advantage of three difficulty levels and a custom dimension setter. It also keeps track of the high score (or low score, rather) for each difficulty. With easy controls and relatively fast loading times, this program is worth trying!

Since this is the first release of the program, please help me modify it by either identifying bugs or critiquing various elements. Other ideas for improvement are welcome.

The ListPages module does not work recursively.

TI-Basic Developer

The TI-Basic Information Repository

The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.
The ListPages module does not work recursively.

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.