Program Syntax
Basic256 programs consist of a series of statements separated by newlines, which are executed in order.
Numeric Constants
Numeric constants are any numeric characters, preceded by an optional minus sign to indicate negative numbers, and an optional decimal followed by more numeric characters to indicate floating point values.
String Constants
String constants are zero or more characters enclosed by double quotation marks(").
Variables
Variables that hold numeric values must begin with a letter, and may consist of any number of alpha-numeric characters. They are case sensitive. They may be used interchangeably with numeric constants.
Variables that hold string values follow the same rules as numeric variables, but must end with a dollar sign ($). They may be used interchangeably with string constants.
Arrays
Arrays are allocated using the DIM command, and may hold numeric or string data. Access to specific elements in an array is accomplished by using square brackets along with the integer offset of the element, starting from zero. For example:
myarray[4]
will access the fifth element in 'myarray'.
Anonymous Arrays
An anonymous array is a set of numeric values or a set of string values, separated by commas, and enclosed in braces {}
An anonymous array can be used in place of an array variable, or it can be used to assign to an array variable, as follows:
dim myarray(4)
myarray = {1, 2, 3, 4}
Operators
The operators +, -, *, and / are used to perform addition, subtraction, multiplication, and division of their operands, respectively. Valid operands are numeric constants and/or numeric variables.
The = operator is used both for assignment to variables, and to test for equality.
The + operator may be used to perform concatenation of any combination of string constants and string variables.
The : operator can separate multiple statements on a single line.
The ; operator supresses the new line that is printed from a PRINT statement. Example:
print "hello";
The # operator is a shortcut for the REM statement, and is interchangeable with it.
Command reference
| Command |
Abs |
| Format |
abs ( expression ) |
| Description |
Returns the absolute value of expression |
| Command |
Ceil |
| Format |
ceil ( expression ) |
| Description |
Returns the lowest integer that is greater than or equal to expression |
| See Also |
Floor |
| Command |
Circle |
| Format |
circle x,y,r |
| Description |
Draws a circle centered at x,y with a radius r using the current color. |
| Command |
Clg |
| Format |
clg |
| Description |
Clears the graphics output window. |
| Command |
Close |
| Format |
close |
| Description |
Closes the currently open file. If no file is open, this command does nothing. |
| See Also |
Open, Read, Write, Reset |
| Command |
Cls |
| Format |
cls |
| Description |
Clears the text output window. |
| Command |
Color |
| Format |
color colorname |
| Description |
Sets the current drawing color to colorname. |
| Command |
Cos |
| Format |
cos ( expression ) |
| Description |
Computes the cosine of expression. Expression must be in radians. |
| Note |
The cos function does not produce an exact result. |
| See Also |
Sin, Tan |
| Command |
Dim |
| Format |
dim ( integer ) |
| Description |
Returns a newly created array of length integer. Depending on the variable assignment, a string or numerical array is created. |
| Command |
End |
| Format |
end |
| Description |
Halts program execution. |
| Command |
FastGraphics |
| Format |
fastgraphics |
| Description |
Turns fastgraphics mode on, until the program is halted. Fastgraphics mode means that the graphics display is not updated until a REFRESH command is issued. It can be used to significantly speed up complex animations and eliminate flicker. |
| Note |
When doing animation, it's recommended to do all of your drawing commands in subroutines and use a single REFRESH command after all drawing has been done for that frame. |
| Command |
Floor |
| Format |
floor ( expression ) |
| Description |
Returns the greatest integer that is less than or equal to expression |
| See Also |
Ceil |
| Command |
For/Next |
| Format |
for variable = expression1 to expression2 [ step expression3 ] ... next variable |
| Description |
The FOR and NEXT commands are used in conjunction to execute a command or group of commands a specified number of times. When the FOR command is first encountered, the variable is set to expresssion1. After each NEXT command, variable is incremented by 1 (the default), or by expression3 if the optional STEP is used, until variable is greater than or equal to expression2 for positive step values, or less than or equal to expression2 for negative step values. |
| Command |
Goto |
| Format |
goto label |
| Description |
Jumps to the specified label. |
| Command |
Gosub / Return |
| Format |
gosub label ... return |
| Description |
Jumps to the specified label. Upon encountering a RETURN command, program execution will continue at the line following the GOSUB. GOSUB commands may be nested. |
| Command |
Instr |
| Format |
instr string1, string2 |
| Description |
Check to see if string2 is contained in string1. If it is, then this function will return the index of starting character of the first place where string2 occurs. Otherwise, this function will return 0. |
| Note |
String indices begin at 1. |
| Example |
The line print instr("Hello", "lo") will print 4 |
| Command |
Int |
| Format |
int ( expression ) int ( string expression ) |
| Description |
Convert to an integer. Int will truncate the decimal values of a floating point number, or will convert a string to an integer. |
| Command |
If / Then |
| Format |
if booleanexpr then statement |
| Description |
Evaluates booleanexpr. If true, then statement is executed. If false, statement is ignored and execution continues at the beginning of the next line. |
| Command |
Input |
| Format |
input string, stringvar |
| Description |
Waits for the user to type a line of text into the text output window. When the user hits the enter or return key, the line is read in to stringvar. |
| Command |
Key |
| Format |
key |
| Description |
Immediately returns an integer value corresponding to the currently pressed keyboard key. |
| Note |
This code
if key = 47 then print key will not work, because it's calling key twice in succession, and will return different values each time. This code will do what you want:
a = key
if a = 47 then print a |
| Command |
Length |
| Format |
length string |
| Description |
Returns the number of characters in string |
| Command |
Line |
| Format |
line x0, y0, x1, y1 |
| Description |
Draws a line from the point x0,y0 to the point x1, y1. |
| Command |
Mid |
| Format |
mid string, start character, length |
| Description |
Returns a portion of the specified string, starting from the start character, and continuing for length characters. |
| Example |
The line print mid("Hello", 2, 3) will print ell |
| Command |
Open |
| Format |
open filename |
| Description |
Opens a file for reading and writing. The filename is specified as a string, and may be an absolute or relative path. |
| Note |
Only one file may be open at a time. Opening a file while another is already open will close the open file. |
| See Also |
Close, Read, Write, Reset |
| Command |
Pause |
| Format |
pause seconds |
| Description |
Halts execution for the specified number of seconds. The seconds value may be a decimal value, so sub-second precision is possible. |
| Command |
Plot |
| Format |
plot x, y |
| Description |
Changes the pixel located at x,y in the graphics output window to the current color. |
| Command |
Poly |
| Format |
poly array, segments |
| Description |
Draws a polygon. The sides of the polygon are defined by the values stored in the array, which should be stored as x,y pairs, sequentially. The number of sides must be given as the second argument. |
| Command |
Print |
| Format |
print expression [ ; ] |
| Description |
Writes text to the text output window, appending a new line. If the optional semicolon is included, no new line is appended. |
| Command |
Rand |
| Format |
rand |
| Description |
Returns a random number between 0 and 1. The distribution of the values is uniform. |
| Note |
To produce random numbers between other values, simple multiply or add the appropriate numbers. For example, to generate an integer between 0 and 10, use int(rand * 10). |
| Command |
Read |
| Format |
read |
| Description |
Reads and returns a token from the currently open file. A token is any string of characters that is separated by a space, tab or newline character. |
| See Also |
Open, Close, Write, Reset |
| Command |
Rect |
| Format |
rect x,y,width,height |
| Description |
Draws a width x height pixel rectangle using the current color. The top left corner is located at x,y. |
| Command |
Refresh |
| Format |
refresh |
| Description |
Updates the graphics output window to show all drawing since the previous refresh command. Refresh only works in FastGraphics mode |
| Command |
Rem |
| Format |
rem comment |
| Description |
Line comment. A line beginning with REM is ignored. |
| Command |
Reset |
| Format |
reset |
| Description |
Clears the currently open file. All data stored in the file is lost. |
| See Also |
Open, Read, Close, Write |
| Command |
Sin |
| Format |
sin ( expression ) |
| Description |
Computes the sine of expression. Expression must be in radians. |
| Note |
The sin function does not produce an exact result. |
| See Also |
Cos, Tan |
| Command |
String |
| Format |
string ( expression ) |
| Description |
Returns the string representation of a number. |
| Command |
Tan |
| Format |
tan ( expression ) |
| Description |
Computes the tangent of expression. Expression must be in radians. |
| Note |
The tan function does not produce an exact result. |
| See Also |
Sin, Cos |
| Command |
Write |
| Format |
write string |
| Description |
Writes string to the end of the currently open file. |
| See Also |
Open, Read, Close, Reset |