Table of Contents

Export page to Open Document format

BASIC-256 Syntax Reference

Syntaxe du programme

Les programmes sous BASIC-256 sont formés d'une série d'instructions séparées par un retour à la ligne et qui sont exécutées dans l'ordre.

2010/09/05 17:27

Constantes numériques

Les constantes numériques peuvent être n'importe quel(s) caractère(s) numérique(s), précédé ou non d'un signe moins (pour les nombres négatifs) et une éventuelle décimale (pour les nombres à virgule flottante).

Les nombres positifs entiers peuvent aussi être exprimées en binaire (base 2), octal (base 8) et hexadécimal (base 16). Faites précéder les entrées binaires de 0b (0b1110 = 14), octales de 0o (0o177 = 127) et hexadécimales de 0x (0xff = 255).

2010/09/05 17:27

Constantes chaînes de caractères

Les (constantes) chaînes de caractères sont composées de zéro ou plus de caractères entourés de guillemets (”).

2010/09/05 17:27

Variables

Le nom des variables contenant des valeurs numériques doit commencer par une lettre et peut comporter n'importe quel nombre de caractères alpha-numériques. Il est sensible à la casse (on différencie majuscule et minuscule). Il peut être utilisé en alternance de constantes numériques (i.e. on peut passer de l'un à l'autre, les deux se valent).

Le nom des variables contenant des chaînes de caractères suit les mêmes règles que celui des variables numériques, mais doit finir par un symbole dollar ($). Il peut, lui aussi, être utilisé en alternance de constantes.

2010/09/05 17:27

Tableaux

Les tableaux sot affectés à l'aide de la commande DIM ou redimensionnés avec Redim. Ils peuvent contenir des données numériques ou des chaînes de caractères. Pour accéder à un élément donné d'un tableau on utilise les crochets ”[ et ]” autour du rang de l'élément voulu (la numérotation partant de zéro). Les tableaux peuvent aussi dimensionnés et interrogés sur 2 dimensions.
Le taille d'un tableau peut être retournée par une des commandes suivantes : [?] [?,] ou [,?] à la fin du nom du tableau.

Exemple

print myarray[4]

affichera à l'écran le 5eme élément du tableau 'myarray'

2010/09/05 17:26

Tableaux "anonymes"

Un tableau anonyme est une série de valeurs numériques ou de chaînes de caractères, séparées par des virgules, et encadrées par des accolades {}. Un tableau anonyme peut ête utilisé à la place d'une variable d'un tableau ou pour assigner une variable d'un tableau.

Exemple

dim myarray(4)
myarray = {1, 2, 3, 4}

PS : je ne suis pas sûr de la traduction de cette page. C'est ainsi que je l'ai compris, mais sans certitude.

2010/09/05 17:26

Opérateurs

Les opérateurs +, -, *, /, ^, %, et  sont utilisés pour réaliser respectivement une addition, une soustraction, une multiplication, une division, une puissance, un modulo et une division arrondie à l'entier des opérandes. Les opérandes valides sont des constantes numériques et/ou des varaibles numériques.

L'opérateur = est utilisé à la fois pour assigner une valeur à une varaiable et pour tester l'égalité. L'opérateur + peut être utilisé pour réaliser la concaténation (= mise bout à bout) de n'importe quelle combinaison de chaînes de constantes et de variables.string variables. L'opératuer : peut servir à séparer plusieurs instructions sur une même ligne. L'opérateur ; supprime le retour à la ligne qu'introduirait une commande PRINT. L'opérateur # est un raccourci de la commande Rem et interchangeable avec celle-ci.

Ordre des opérations
NiveauOpérateurCatégorie/Description
1( )Groupement
2^Exposant
3-Moins
4* / \Multiplication et Division
5%Reste entier (Mod)
6+ -Addition, Concaténation et Soustraction
7< ⇐ > >= = <>Comparaison (Numérique et Chaîne)
8NOT“Non” logique
9AND“Et” logique
10OR“Ou” logique
11XOR“Ou exclusif” logique
2010/09/05 17:27

Statements and Functions - Alphabetic

Abs

Format

abs ( expression )

Description

Retourne la valeur absolue d'une expression numérique.

Exemple
print abs(-45)
print abs(6.45)

permet d'afficher

45
6.45
2010/09/05 17:26

Acos

Format

acos ( expression )

Description

Calcule l'arc-cosinus d'expression. Les angles sont exprimés en radians (0 à 2 pi).

Voir Aussi
2010/09/05 17:26

Asc

Format

asc ( expression )

Description

Convertit le premier caractère d'une chaîne en sa valeur ASCII (= un nombre entier).

AscChrAscChrAscChrAscChrAscChrAscChr
32SPACE48064@80P96`112p
33!49165A81Q97a113q
3450266B82R98b114r
35#51367C83S99c115s
36$52468D84T100d116t
37%53569E85U101e117u
38&54670F86V102f118v
39'55771G87W103g119w
40(56872H88X104h120x
41)57973I89Y105i121y
42*58:74J90Z106j122z
43+59;75K91[107k123{
44,60<76L92\108l124|
45-61=77M93]109m125}
46.62>78N94^110n126~
47/63?79O95_111o127

Voir Aaussi

Chr

Exemple

print asc("A")
print asc("bleu")

permet d'afficher

65
98

Fonction disponible de la version

0.9.4

2010/09/05 17:26

Asin

Format

asin ( expression )

Description

Calcule l'arc-sinus d'une expression. Les angles sont exprimés en (0 à 2pi).

Voir aussi

2010/09/05 17:26

Atan

Format

atan ( expression )

Description

Calcule l'arc-tangente d'une expression. Les angles sont exprimés en radians (0 à 2pi).

Voir aussi

2010/09/05 17:27

Ceil

Format

ceil ( expression )

Description

REtourne l'entier immédiatement inférieur ou égal à une expression.

Voir aussi

Exemple

print ceil(9.1)
print ceil(-5.4)

fera afficher

10
-5
2010/09/05 17:27

Changedir

Format

changedir expression
changedir ( expression )

Description

Change de répertoire de travail pour le chemin spécifié par l'expression. Pour toutes le OS (y compris Windows) un anti-slash (/) est utilisé pour séparer les répertoire au sein d'un chemin complet.

Voir aussi

Disponible à partir de la version

0.9.6r

2010/09/05 17:27

Chr

Format

chr ( expression )

Description

Converti l'entier expression en le caractère correspondant en code ASCII. Voir la page consacrée à asc pour un tableau de converson des caractères ASCII.

Voir aussi

Asc

Exemple

print chr(66)+chr(111)+chr(111)+chr(33)

affichera

Boo!

Disponible à partir de la version

0.9.4

2010/09/05 17:27

Circle

Format

circle x,y,r

Description

Trace un cercle dont les coordonnées du centre sont x,y et le rayon r. Le cercle étant de la couleur active.

Exemple

color blue
rect 0,0,300,300
color red
circle 100,100,50

dessine
Circle

2010/09/05 17:27

Clickb

Format

clickb
clickb ( )

Description

Retourne quel(s) bouton(s) de la souris l'utilisateur a pressé (quand il est sur la partie graphic output). Retourne 0 si aucun clic n'a été détecté. Si plusieurs boutons ont été pressés la valeur est la somme des valeurs des boutons pressés.

Valeurs retournées
ValeurBouton pressé
0aucun
1gauche
2droit
4du centre

Voir aussi

Exemple

# réinitialise le compte des clics
clickclear
# attend que l'utilisateur clique
print "cliquez avec la souris sur la surface graphics output"
while clickb = 0
  pause .01
endwhile
# Montre où l'utilisatur a cliqué
print "L'utilisateur a cliqué le point de coordonnées (" + clickx + "," + clicky + ")"

Disponible à partir de la version

0.9.4d

2010/09/05 17:27

Clickclear

Format

clickclear
clickclear ( )

Description

Remet ClickB, Clickx et Clicky à zéro afin de pouvoir détecter facilement un clic de la souris.

Voir aussi

Exemple

Voir le programme de la page de Clickb.

Disponible à partir de la version

0.9.4d

2010/09/05 17:27

Clickx

Format

clickx
clickx ( )

Description

Retourne l'abscisse x du pointeur de la souris sur la surface graphic output au dernier clic.

Voir aussi

Exemple

Voir le programme de la page de Clickb.

Disponible à partir de la version

0.9.4d

2010/09/05 17:27

Clicky

Format

clicky
clicky ( )

Description

Retourne l'ordonnée y du pointeur de la souris sur la surface graphic output au dernier clic.

Voir aussi

Exemple

Voir le programme sur la page de Clickb.

Disponible à partir de la version

0.9.4d

2010/09/05 17:27

Clg

Format

clg

Description

Clears the graphics output window.

2010/09/05 17:27

Close

Format

close
close ( )
close filenumber
close ( filenumber )

Description

Ferme un fichier ouvert. Di aucun fichier n'est ouvert à ce numéro, la commande n'a aucun effet. Si aucun numéro de fichier n'est spécifié, le numéro de fichier utilisé sera le zéro.

Voir aussi

2010/09/05 17:27

Cls

Format

cls

Description

Nettoie la fenêtre text output.

2010/09/05 17:27

Color

Format

color colorname
color ( colorname )
color red, blue, green
color ( red, blue, green )
color rgb_value
color ( rgb_value )

Description

Règle la couleur active comme étant la couleur appelée colorname; de composantes rouge, bleue et verte red, blue, green ; ou de valeur RGB rgb_value.

Il y a une couleur spéciale appelée CLEAR, de valeur -1. Si la couleur courante est réglée sur cette valeur, les pixels ou formes dessinés effaceront les pixels sur lesquels ils passeront et les rendront transparents. C'est particulièrement utile pour créer des sprites avec la commande Spriteslice.

Noms des couleurs et leur valeur RGB
Nom de la couleurValeur RGB
black0, 0, 0        
white255, 255, 255        
red255, 0, 0        
darkred128, 0, 0        
green0, 255, 0        
darkgreen0, 128, 0        
blue0, 0, 255        
darkblue0, 0, 128        
cyan0, 255, 255        
darkcyan0, 128, 128        
purple255, 0, 255        
darkpurple128, 0, 128        
yellow255, 255, 0        
darkyellow128, 128 ,0        
orange255, 102, 0        
darkorange176, 61 ,0        
grey164, 164 ,164        
darkgrey128, 128 ,128        
clear-1 

Voir aussi

Exemple

clg
color rgb(128,128,128)
rect 0,0,graphwidth, graphheight
color red
circle 100,100,50
color 255,160,160
circle 100,100,25

Dessinera un rectangle gris avec dedans un cercle rouge et un centre rose.
Color

Disponible à partir de la version

0.9.5m

2010/09/05 17:27

Cos

Format

cos ( expression )

Description

Calcule le cosinus de l'expression. L'expression doit être exprimé en radians.

Note

La fonction cos ne retourne pas un résultat exact (mais une valur approchée).

Voir aussi

Exemple

clg
color black
# Trace une ligne à travers la fenêtre graphic output
line 0,150,300,150
# point de départ
lastx = 0
lasty = cos(0) * 50 + 150
# puis pas après pas trace la courbe du cosinus
for x = 0 to 300 step 5
   angle = x / 300 * 2 * pi
   y = cos(angle) * 50 + 150
   line lastx, lasty, x, y
   lastx = x
   lasty = y
next x

dessine
Cosine Curve

2010/09/05 17:27

Currentdir

Format

currentdir
currentdir ( )

Description

Retourne le chemin complet du répertoire courant. Pour toutes les OS (y compris Windows) un anti-slash (/) sépare les répertoires du chemin.

SeVoir aussi

Disponible à partir de la version

0.9.6r

2010/09/05 17:27

Day

Format

day
day ( )

Description

Retourne le jour du mois actuel (1-31) d'après l'horloge système.

Voir aussi

Exemple

print "Aujourd'hui nous sommes le ";
print day + "/" + (month + 1) + "/" + year

affichera|

Aujourd'hui nous sommes le 12/09/2010

Disponible à partir de la version

0.9.4

2010/09/05 17:27

DBClose

Format

dbclose
dbclose ( )

Description

Ferme le fichier de données SQLite actuellement ouvert.

Exemple

Voir l'exemple de la page de DBOpen.

Voir aussi

Liens externes

De plus amples informations (en anglais) sur les bases de données en général et SQLite en particulier sont disponibles aux adresses suivantes : SQLite Home Page et SQL at Wikipedia.

Disponible à partir de la version

0.9.6y

2010/09/05 17:27

DBCloseSet

Format

dbcloseset
dbcloseset ( )

Description

Close the currently open record set opened by DBOpenSet.

Example

See example of usage on DBOpen page.

See Also

External Links

More information about databases in general and SQLite specifically can be found at SQLite Home Page and SQL at Wikipedia.

New To Version

0.9.6y

2010/09/05 17:27

DBExecute

Format

dbexecute SqlStatement
dbexecute ( SqlStatement )

Description

Exécute une commande SQL sur le fichier de base de données SQLite ouvert. Cette commande ne produit pas d'enregistrement.

Exemple

Voir l'exemple de la page de DBOpen.

Voir aussi

Liens externes

De plus amples informations (en anglais) sur les bases de données en général et SQLite en particulier sont disponibles aux adresses suivantes : Page d'accueil de SQLite et SQL sur Wikipedia.

Disponible à partir de la version

0.9.6y

2010/09/05 17:27

DBFloat

Format

dbfloat ( ColumnNumber )

Description

Retounrne une valeur décimale (virgule flottante) de la colonne demandée de la ligne active de l'enregistrement ouvert.

Exemple

Voir l'exemple de la page de DBOpen.

Voir aussi

Liens externes

De plus amples informations (en anglais) sur les bases de données en général et SQLite en particulier, sont disponibles aux adresses suivantes : Page d'accueil de SQLite et SQL sur Wikipedia.

Disponible à partir de la version

0.9.6y

2010/09/05 17:27

DBInt

Format

dbint ( ColumnNumber )

Description

Retourne la valeur entière de la colonne demandée de la ligne active de l'enregistrement ouvert.

Exemple

Voir l'exemple de la page de DBOpen.

Voir aussi

Liens externes

De plus amples informations (en anglais) sur les bases de données en général et SQLite en particulier, sont disponibles aux adresses suivantes : Page d'accueil de SQLite et SQL sur Wikipedia.

Disponible à partir de la version

0.9.6y

2010/09/05 17:27

DBOpen

Format

dbopen SQLiteFile
dbopen ( SQLiteFile )

Description

Ouvre un fichier de base de données SQLite. Si le fichier n'existe pas, il est créé.

Exemple

#database foo - crée une base de données, peuple une table, ouvre un enregistrement et lit les données de la table.

# crée un nouveau fichier de base de données ou l'ouvre
dbopen "dbtest.sqlite3"

# efface l'ancienne foo table - renvoie une erreur si c'est une nouvelle base de données
onerror errortrap
dbexecute "drop table foo;"
offerror
# crée et peuple
dbexecute "create table foo (id integer, words text, value decimal);"
dbexecute "insert into foo values (1,'one',3.14);"
dbexecute "insert into foo values (2,'two',6.28);"
dbexecute "insert into foo values (3,'three',9.43);"

# ouvre un enregistrement et tourne en boucle  à travers les lignes de données
dbopenset "select * from foo order by words;"
while dbrow()
	print dbint(0) + dbstring(1) + dbfloat(2)
end while
dbcloseset

# rassemble tout
dbclose
end

errortrap:
# accepte l'erreur - n'affiche rien - va à la prochaine commande
return

affichera

1one3.14
3three9.43
2two6.28

Voir aussi

Lien externes

De plus amples informations (en anglais) sur les bases de données en général et SQLite en particulier, sont disponibles aux adresses suivantes : Page d'accueil de SQLite et SQL sur Wikipedia.

Disponible à partir de la version

0.9.6y

2010/09/05 17:27

DBClose

Format

dbopenset SqlStatement
dbopenset ( SqlStatement )

Description

Perform an SQL statement and create a record set so that the program may loop through and use the results.

Example

See example of usage on DBOpen page.

See Also

External Links

More information about databases in general and SQLite specifically can be found at SQLite Home Page and SQL at Wikipedia.

New To Version

0.9.6y

2010/09/05 17:27

DBRow

Format

dbrow
dbrow ( )

Description

Function that advances the record set to the next row. Returns a true value if there is a row or false if we are at the end of the record set.

Example

See example of usage on DBOpen page.

See Also

External Links

More information about databases in general and SQLite specifically can be found at SQLite Home Page and SQL at Wikipedia.

New To Version

0.9.6y

2010/09/05 17:27

DBString

Format

dbstring ( ColumnNumber )

Description

Return a string from the specified column of the current row of the open recordset.

Example

See example of usage on DBOpen page.

See Also

External Links

More information about databases in general and SQLite specifically can be found at SQLite Home Page and SQL at Wikipedia.

New To Version

0.9.6y

2010/09/05 17:27

Degrees

Format

degrees ( expression )

Description

Convertis un angle en radians en degrés.

Voir aussi

2010/09/05 17:27

Dim

Format

dim numericvariable ( integer )
dim stringvariable$ ( integer )
dim numericvariable ( rows , columns )
dim stringvariable$ ( rows , columns )

Description

Retourne un nouveau tableau à 1 dimension de longueur integer ou à 2 dimensions qui peut être adressé par row et column. Selon l'assignation de la variable, un tableau numérique ou de chaînes de caractères est créé.
Le premier élément d'un tableau a l'index 0 (zéro). Les index allant ainsi de 0 à {longueur}-1.

Voir aussi

Exemple

dim z(5)
z = {1, 2, 3, 4, 5}
print z[0] + " " + z[4]

affichera

1 5

Exemple 2

dim c$(4)
c$ = {"à", "bulot, "laque", "L'anneau"}
print c$[2] + " " + c$[3] + " ";
print c$[1] + " " + c$[0] + "!"

affichera

L'anneau laque à bulot!
2010/09/05 17:27
 

End

Format

end

Description

Halts program execution.

Example

print "I am done."
end
print "Or am I?"

will print

I am done.
2010/09/05 17:27

Eof

Format

eof
eof()
eof(filenumber)

Description

Returns a binary flag (true/false) that will signal if we have read to the End Of File (EOF). If file number is not specified then file number zero (0) will be used.

See Also

New To Version

0.9.4

2010/09/05 17:27

Exists

Format

exists ( expression )

Description

Returns a binary flag (true/false) that will signal if the file path specified by the expression exists.

See Also

New To Version

0.9.4

2010/09/05 17:27

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.

See Also

2010/09/05 17:27

Float

Format

float ( expression )

Description

Convert expression to a floating point (decimal) number. Float will convert a string or an integer to a decimal value. If the expression can not be converted then a zero will be returned.

See Also

Int

New To Version

0.9.4

2010/09/05 17:27

Floor

Format

floor ( expression )

Description

Returns the greatest integer that is less than or equal to expression

See Also

2010/09/05 17:27

Font

Format

font fontname, point, weight

Description

Sets the font used by the text command to fontname. Size is defined in points (1/72”) Weight represents a number from 1 to 100 that defines how dark the letters will be drawn. Light=25, Normal=50, and Bold=75.

Example

color grey
rect 0,0,graphwidth,graphheight
color red
font "Times New Roman",18,50
text 10,100,"This is Times New Roman"
color darkgreen
font "Tahoma",28,100
text 10,200,"This is BOLD!"

Will draw.

See Also

New To Version

0.9.4

2010/09/05 17:27
 

GetColor

Format

getcolor
getcolor()

Description

Returns the RGB value of the current drawing color (last set by color statement). RGB is calculated by taking ((red * 256) + green * 256) + blue where red, green, and blue are between 0 and 255. If the drawing color has been set to CLEAR a -1 will be returned.

See Also

Example

color red
print getcolor

will print

16711680

New To Version

0.9.5m

2010/09/05 17:27

GetSlice

Format

getslice(x, y, width, height)

Description

Return a string that contains a Hexadecimal representation of the rectangle defined by the parameters. String is formatted as first 4 bytes - width, next 4 bytes - height, 6 bytes for each pixel (width * height).

See Also

New To Version

0.9.6b

2010/09/05 17:27

Goto

Format

goto label

Description

Jumps to the specified label.

See Also

Example

print "I";
goto skipit
print " don't";
skipit: #
print " want cookies."

will print

I want cookies.
2010/09/05 17:27
 

Graphheight

Format

graphheight
graphheight()

Description

Returns the height (y dimension) of the current graphics display window.

See Also

New To Version

0.9.3

2010/09/05 17:27

Graphsize

Format

graphsize x_expression, y_expression

Description

Changes the size of the graphics display window and redraws the BASIC256 application.

See Also

New To Version

0.9.3

2010/09/05 17:27

Graphwidth

Format

graphwidth
graphwidth()

Description

Returns the width (x dimension) of the current graphics display window.

See Also

New To Version

0.9.3

2010/09/05 17:27

Hour

Format

hour
hour()

Description

Returns the current system clock's hour of the day (0-23).

Example

# display nice date
dim months$(12)
months$ = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
print year + "-" + months$[month] + "-" + right("0" + day, 2)
# display pretty time
h = hour
if h > 12 then
h = h - 12
ampm$ = "PM"
else
ampm$ = "AM"
end if
if h = 0 then h = 12
print  right("0" + h, 2) + "-" + right("0" + minute, 2) + "-" + right("0" + second, 2) + " " + ampm$

Will print something like.

2010-July-15
10-00-02 PM

See Also

New To Version

0.9.4

2010/09/05 17:27

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

print instr("Hello", "lo")

will display

4
2010/09/05 17:27

Int

Format

int ( expression )

Description

Convert expression to an integer (whole) number. Int will convert a string or a float to an integer value. If the expression can not be converted then a zero will be returned.

See Also

2010/09/05 17:27
 

Imgload

Format

imgload x, y, filename
imgload x, y, scale, filename
imgload x, y, scale, rotation, filename

Description

Load an image or picture from a file and paint it on the Graphics Output Window.
The parameters x and y represent the location on the screen for the CENTER of the loaded image. This behaviour is different than all of the other graphics statements. The axis of rotation will also be this CENTER point.\\The Imgload starement will read in most common image file formats including: BMP (Windows Bitmap), GIF (Graphic Interchange Format),JPG/JPEG (Joint Photographic Experts Group), and PNG (Portable Network Graphics).
Optionally scales size of the loaded image by the defined scale (1=normal size). Also optionally rotates the image by a specified angle around the images center (clockwise in radians).

New To Version

0.9.6l

2010/09/05 17:27

Input

Format

input expression, stringvariable
input expression, numericvariable
input stringvariable
input numericvarvariable

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 or numericvariable.
User may optionally be prompted for the input by expression.
If a numeric variable is specified and non-numeric data is entered a zero will be assigned to the numeric variable.
References to array elements may also be specified.

2010/09/05 17:27

Key

Format

key
key()

Description

Immediately returns an integer value corresponding to the currently pressed keyboard key. If no key has been pressed since the last call to the key function then the number zero (0) will be returned.

Note

if key = 47 then print key

will not display the desired results, 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
2010/09/05 17:27

LastError

Format

lasterror
lasterror ( )

Description

Returns the last runtime error number.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

LastErrorExtra

Format

lasterrorextra
lasterrorextra ( )

Description

Returns statement specific “extra” information about the error.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

LastErrorLine

Format

lasterrorline
lasterrorline ( )

Description

Returns the line number in the program where the runtime error happened.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

LastErrorMessage

Format

lasterrormessage
lasterrormessage ( )

Description

Returns a string representing the last runtime error.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

Left

Format

left( string, length)

Description

Returns a portion of the specified string, starting from the first character on the left and continuing for length characters.

See Also

Example

print left("Hello", 2)

will display

He

New To Version

0.9.5b

2010/09/05 17:27

Length

Format

length( string )

Description

Returns the number of characters in string

2010/09/05 17:27

Line

Format

line x0, y0, x1, y1
line(x0, y0, x1, y1)

Description

Draws a line from the point x0,y0 to the point x1, y1.

Example

color white
rect 0,0,300,300
color black
line 50,50,200,200
line 100,200,200,200
line 100,200,50,50

draws
Line

2010/09/05 17:27

Log

Format

log ( expression )

Description

Return the base e lograthim of expression.

See Also

New To Version

0.9.5w

2010/09/05 17:27
 

Lower

Format

lower( string)

Description

Returns string with all alphabetic characters converted to lower case.

See Also

Upper

print lower("BlUe!")

will display

blue!

New To Version

0.9.5e

2010/09/05 17:27

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.

See Also

Example

print mid("Hello", 2, 3)

will display

ell
2010/09/05 17:27

Minute

Format

minute
minute()

Description

Returns the current system clock's minute of the hour (0-59).

Example

# display nice date
dim months$(12)
months$ = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
print year + "-" + months$[month] + "-" + right("0" + day, 2)
# display pretty time
h = hour
if h > 12 then
h = h - 12
ampm$ = "PM"
else
ampm$ = "AM"
end if
if h = 0 then h = 12
print  right("0" + h, 2) + "-" + right("0" + minute, 2) + "-" + right("0" + second, 2) + " " + ampm$

Will print something like.

2010-July-15
10-00-02 PM

See Also

New To Version

0.9.4

2010/09/05 17:27

Month

Format

month
month()

Description

Returns the current system clock's month. January is 0, February is 1… December is 11.

See Also

Example

cls
dim n$(12)
n$ = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}
print day + "-" + n$[month] + "-" + year

on New Years will display

1-Jan-2010

New To Version

0.9.4

2010/09/05 17:27

Mouseb

Format

mouseb
mouseb()

Description

Returns the buttons that currently pressed on the mouse (if over the graphic output). Returns 0 if no click has been recorded. If multiple buttons have been pressed the value is the sum of the values for all pressed buttons.

Return Values
ValueMouse Button Pressed
0None
1Left
2Right
4Center

See Also

New To Version

0.9.4d

2010/09/05 17:27

Mousex

Format

mousex
mousex()

Description

Returns the current or last mouse x location of the mouse pointer over the graphic output.

See Also

New To Version

0.9.4d

2010/09/05 17:27

Mousey

Format

mousey
mousey()

Description

Returns the current or last mouse y location of the mouse pointer over the graphic output.

See Also

New To Version

0.9.4d

2010/09/05 17:27

NetClose

Format

netclose
netclose ( )
netclose socket_number
netclose ( socket_number )

Description

Close the specified network connection (socket). If socket_number is not specified socket number zero (0) will be used.

Example

See example of usage on NetConnect page.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

NetConnect

Format

netconnect server_name, port_number
netconnect ( server_name, port_number )
netconnect socket_number, server_name, port_number
netconnect ( socket_number, server_name, port_number )

Description

Open a network connection (client) to a server. The IP address or host name of a server are specified in the server_name argument, and the specific network port number in the port_number argument. If socket_number is not specified socket number zero (0) will be used.

Example

Open two instances of BASIC-256 on a single computer. Paste the “server” code into one and the “client” code into the other. Run the server first and the client second. You can see how the messages are sent back and forth between the two different processes.

Server Code

# get a message and send back success
print "wait for connection"
netlisten 9997
print "got connection"
do
   while not netdata
      pause .1
      print ".";
   end while
   n$ = netread
   print n$
   netwrite "I got '" + n$ + "'."
until n$ = "end"
netclose

will display

wait for connection
got connection
.1 Hi There
....2 Hi There
........3 Hi There
..........4 Hi There
.....5 Hi There
.......6 Hi There
....7 Hi There
..........8 Hi There
....9 Hi There
.....10 Hi There
.end

Client Code

# have the user enter a message and send it to the server
input "enter message?", m$
netconnect "127.0.0.1", 9997
for t = 1 to 10
   pause rand
   netwrite t + " " + m$
   print netread
next t
netwrite "end"
print netread
netclose

will display

enter message?Hi There
I got '1 Hi There'.
I got '2 Hi There'.
I got '3 Hi There'.
I got '4 Hi There'.
I got '5 Hi There'.
I got '6 Hi There'.
I got '7 Hi There'.
I got '8 Hi There'.
I got '9 Hi There'.
I got '10 Hi There'.
I got 'end'.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

NetData

Format

netdata
netdata ( )
netdata socket_number
netdata ( socket_number )

Description

Returns a true value (1) of there is data waiting to be read in using the NetRead function, else returns false (0). If socket_number is not specified socket number zero (0) will be used.

Example

See example of usage on NetConnect page.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

NetListen

Format

netlisten port_number
netlisten ( port_number)
netlisten socket_number, port_number
netlisten ( socket_number, port_number)

Description

Open up a network connection (server) on a specific port address and wait for another program to connect. If socket_number is not specified socket number zero (0) will be used.

Example

See example of usage on NetConnect page.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

NetRead

Format

netread
netread ( )
netread ( socket_number )

Description

Read data from the specified network connection and return it as a string. This function will wait until data is received. If socket_number is not specified socket number zero (0) will be used.

Example

See example of usage on NetConnect page.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

NetWrite

Format

netwrite string
netwrite ( string )
netwrite socket_number, string
netwrite ( socket_number, string )

Description

Send a string to the specified open network connection. If socket_number is not specified socket number zero (0) will be used.

Example

See example of usage on NetConnect page.

See Also

New To Version

0.9.6.31

2010/09/05 17:27

Open

Format

open filename
open(filename)
open filenumber, filename
open(filenumber, filename)

Description

Opens a file for reading and writing. The filename is specified as a string, and may be an absolute or relative path. If the file number is not specified file number zero (0) will be used.

Note

BASIC256 may have up to 8 files open at a single time. The files are numbered from 0 to 7. Opening a file to a number while another is already open to that number will close the open file.

See Also

2010/09/05 17:27

OffError

Format

offerror

Description

Turns off error trapping and restores the default error behavior.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

OnError

Format

onerror label

Description

Causes the subroutine at label to be executed when an runtime error occurs. Program control may be resumed at the next statement with a Return statement in the subroutine.

Example

See example of usage on Error Codes page.

See Also

New To Version

0.9.6z

2010/09/05 17:27

Pause

Format

pause seconds
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.

2010/09/05 17:27

Pixel

Format

pixel (x, y )

Description

Returns the RGB value of the pixel at the x and y coordinate. If the pixels has not been set since the last Clg command or was drawn with the color CLEAR a -1 will be returned.

See Also

Rgb

New To Version

0.9.5m

2010/09/05 17:27

Plot

Format

plot x, y
plot ( x, y )

Description

Changes the pixel located at x,y in the graphics output window to the current color.

2010/09/05 17:27

Poly

Format

poly numeric array variable
poly {x1, y1, x2, y2, x3, y3 …}

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 length of the array/2 will define the number of points. A polygon may also be specified using a list of x,y pairs enclosed in curly braces {}.

Note

The number of points in the array argument was removed from the poly statement in version 0.9.4.

See Also

Example

color blue
rect 0,0,300,300
color green
dim tri(6)
tri = {100, 100, 200, 200, 100, 200}
poly tri
color blue
rect 0,0,300,300
color green
poly {100, 100, 200, 200, 100, 200}

Both programs use the poly statement to draw the following:

2010/09/05 17:27

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.

See Also

2010/09/05 17:27

PutSlice

Format

putslice x, y, slice$
putslice x, y, slice$, transparent color

Description

Put the graphics stored in the slice string on the screen at x,y. If a transparent color is specified then do not plot points of that color in the slice.

See Also

New To Version

0.9.6b

2010/09/05 17:27

Radians

Format

radians ( expression )

Description

Converts an angle in degrees to radians.

See Also

2010/09/05 17:27

Rand

Format

rand
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).

2010/09/05 17:27

Read

Format

read
read()
read(filenumber)

Description

Reads and returns a token from an open file. A token is any string of characters that is separated by a space, tab, or newline character. If the file number is not specified file number zero (0) will be used.

See Also

2010/09/05 17:27

Readline

Format

readline
readline()
readline(filenumber)

Description

Reads and returns an entire line from an open file. If the file number is not specified file number zero (0) will be used.

See Also

2010/09/05 17:27

Rect

Format

rect x,y,width,height
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.

Example

color white
rect 0,0,300,300
color red
rect 50,50,150,150
color blue
rect 100,100,150,150
color green
rect 10,140,280,20

draws

2010/09/05 17:27

Redim

Format

redim numericvariable( integer )
redim stringvariable$( integer )
redim numericvariable( rows , columns )
redim stringvariable$( rows , columns )

Description

Re-sizes a previously created array, preserving data. If an array is enlarged then the new elements will be initialized with zero or the empty string. If an array is reduced in size the elements trimmed from the end are lost.

See Also

Dim

New To Version

0.9.5t

2010/09/05 17:27

Refresh

Format

refresh

Description

Updates the graphics output window to show all drawing since the previous refresh command. Refresh only works in Fastgraphics mode

See Also

2010/09/05 17:27

Rem

Format

rem comment
# comment

Description

Line comment. A line beginning with REM (or the shortened #) is ignored.

2010/09/05 17:27

Reset

Format

reset
reset()
reset(filenumber)

Description

Clears an open file. All data stored in the file is lost. If the file number is not specified file number zero (0) will be used.

See Also

2010/09/05 17:27

Rgb

Format

rgb(red, green, blue )

Description

Returns the RGB value of the color made up of the red, green, and blue components. Legal values for red, greem, and blue are 0 to 255.

See Also

New To Version

0.9.5m

2010/09/05 17:27

Right

Format

right( string, length)

Description

Returns a portion of the specified string, starting from the last length characters from the right end of the of the string.

See Also

Example

print right("Hello", 2)

will display

lo

New To Version

0.9.5b

2010/09/05 17:27

Say

Format

say expression say ( expression )

Description

Uses the the system Text to Speech (TTS) engine to say the expression. In LINUX the FLite or eSpeak libraries are required. In Windows the current default SAPI voice will be used.

New To Version

0.9.4

2010/09/05 17:27

Second

Format

second
second()

Description

Returns the current system clock's second of the current minute (0-59).

Example

# display nice date
dim months$(12)
months$ = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
print year + "-" + months$[month] + "-" + right("0" + day, 2)
# display pretty time
h = hour
if h > 12 then
h = h - 12
ampm$ = "PM"
else
ampm$ = "AM"
end if
if h = 0 then h = 12
print  right("0" + h, 2) + "-" + right("0" + minute, 2) + "-" + right("0" + second, 2) + " " + ampm$

Will print something like.

2010-July-15
10-00-02 PM

See Also

New To Version

0.9.4

2010/09/05 17:27

Seek

Format

seek location
seek ( location )
seek filenumber, location
seek ( filenumber, location )

Description

Moves the read/write location to a specific location (offset in bytes from the start of the file) within an open file. If the file number is not specified file number zero (0) will be used.

See Also

New To Version

0.9.4

2010/09/05 17:27

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

Example

clg
color black
# draw a line across the graphic output
line 0,150,300,150
# where do we start
lastx = 0
lasty = sin(0) * 50 + 150
# now step across the line and draw
for x = 0 to 300 step 5
   angle = x / 300 * 2 * pi
   y = sin(angle) * 50 + 150
   line lastx, lasty, x, y
   lastx = x
   lasty = y
next x

Draws Sine Curve

2010/09/05 17:27

Size

Format

size
size()
size(filenumber)

Description

Returns the length, in bytes, of an opened file. If the file number is not specified file number zero (0) will be used.

See Also

New To Version

0.9.4

2010/09/05 17:27

Sound

Format

sound frequency, duration
sound ( frequency, duration )
sound ( array )
sound array
sound {frequency1, duration1, frequency2, duration2, …}

Description

Play a sound from the computer's speakers.Frequency is expressed in Hz and duration is expressed in milliseconds (1000 in a second). An array or list containing frequency and durations may also be passed. This eliminates any clicking between sounds when more than one is being output sequentially. Sound support for LINUX systems was added in version 0.9.5g. Sound was changed to use the default sound device in Windows in version 0.9.5h

See Also

2010/09/05 17:27

Spritecollide

Format

spritecollide ( sprite1, sprite2)

Description

Function returns true if the two sprites are colliding. The Spritecollide function assumes that the sprites are bounded by a rectangle the size of the loaded image. Collision is calculated by using these rectangles. For round or oddly shaped sprites this function may over detect collision.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spritedim

Format

spritedim n
spritedim ( n )

Description

Create n sprite placeholders in memory. Sprites are accessed in your program by a sprite number from 0 to n-1.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spriteh

Format

spriteh ( spritenumber )

Description

Returns the height, in pixels, of a loaded sprite.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spritehide

Format

spritehide spritenumber spritehide ( spritenumber )

Description

Hides a sprite. All image and position information is retained.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spriteload

Format

spriteload spritenumber, filename
spriteload ( spritenumber, filename )

Description

Load an image or picture from a file and save it as a sprite. The sprite will be active and movable but will not display on the screen until the Spriteshow statement is executed for that sprite.\\The Spriteload statement will read in most common image file formats including: BMP (Windows Bitmap), GIF (Graphic Interchange Format),JPG/JPEG (Joint Photographic Experts Group), and PNG (Portable Network Graphics).

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spritemove

Format

spritemove spritenumber, dx, dy
spritemove ( spritenumber, dx, dy )

Description

Move a sprite from its current position by the specified number of pixels. Motion will be limited to the current screen.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spriteplace

Format

spriteplace spritenumber, x, y
spriteplace ( spritenumber, x, y )

Description

Place the center of a sprite at a specific location on the screen. Like Imgload sprite positioning is relative to the center of the sprite and not the top left corner as with most other graphical statements.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spriteshow

Format

spriteshow spritenumber
spriteshow ( spritenumber )

Description

Show a hidden sprite.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spriteslice

Format

spriteslice spritenumber, x, y, width, height
spriteslice ( spritenumber, x, y, width, height )

Description

Copy the rectangular region of the screen with it's top left corner represented by x and y of the specified height and width and create a sprite. The sprite will be active and movable but will not be visible until the Spriteshow statement is executed. It is recommended that you execute the Clg command before drawing and slicing the sprite. All unpainted pixels will be transparent when the sprite is drawn on the screen. Transparent pixels may also be set by drawing with the color CLEAR.

See Also

New To Version

0.9.6o

2010/09/05 17:27

Spritev

Format

spritev ( spritenumber )

Description

Returns true if the sprite is visible.

See Also

New To Version

0.9.6o

2010/09/05 17:27

Spritew

Format

spritew ( spritenumber )

Description

Returns the width, in pixels, of a loaded sprite.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spritex

Format

spritex ( spritenumber )

Description

Returns the x coordinate of the center of a loaded sprite.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Spritey

Format

spritey ( spritenumber )

Description

Returns the y coordinate of the center of a loaded sprite.

See Also

New To Version

0.9.6n

2010/09/05 17:27

Stamp

Format

stamp x, y, array
stamp x, y, {x1, y1, x2, y2, x3, y3 …}
stamp x, y, scale, array
stamp x, y, scale, {x1, y1, x2, y2, x3, y3 …}
stamp x, y, scale, rotation, array
stamp x, y, scale, rotation, {x1, y1, x2, y2, x3, y3 …}

Description

Draws a polygon with top left corner (origin) at x, y. Optionally scales size of polygon by the defined scale (1=normal size). Also optionally rotates the polygon by a specified angle around the origin (clockwise in radians). The sides of the polygon are defined by the values in an array, which should be stored as x,y pairs, sequentially. The length of the array/2 will define the number of points. A stamped polygon can also be specified using a list of x,y pairs enclosed in curly braces {}.

See Also

Example

Both of the code blocks below will draw a pair of green triangles on the graphics window:

clg
color blue
rect 0,0,300,300
color green
dim tri(6)
tri = {0, 0, 100, 100, 0, 100}
# stamp the triangle at 0,0 (full size)
stamp 100, 100, tri
# stamp the triangle at 200,100 (half size)
stamp 200, 100, .5, tri
clg
color blue
rect 0,0,300,300
color green
# stamp the triangle at 0,0 (full size)
stamp 100, 100, {0, 0, 100, 100, 0, 100}
# stamp the triangle at 200,100 (half size)
stamp 200, 100, .5, {0, 0, 100, 100, 0, 100}

Both programs will draw:

New To Version

0.9.4

2010/09/05 17:27

String

Format

string ( expression )

Description

Returns the string representation of a number.

See Also

2010/09/05 17:27

System

Format

system expression
system ( expression )

Description

Execute a system command in a terminal window. WARNING: This can be a very dangerous statement. Only use it if you know what you are doing.

New To Version

0.9.5h

2010/09/05 17:27

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

Example

clg
color black
# draw a line across the graphic output
line 0,150,300,150
# where do we start
lastx = 0
lasty = tan(0) * 50 + 150
# now step across the line and draw
for x = 0 to 300 step 5
   angle = x / 300 * 2 * pi
   y = tan(angle) * 50 + 150
   line lastx, lasty, x, y
   lastx = x
   lasty = y
next x

Draws tan.jpg

2010/09/05 17:27

Text

Format

text x, y, string
text ( x, y, string )

Description

Paints a text string on the Graphics Output Window at x, y using the current color and font.

Example

color grey
rect 0,0,graphwidth,graphheight
color red
font "Times New Roman",18,50
text 10,100,"This is Times New Roman"
color darkgreen
font "Tahoma",28,100
text 10,200,"This is BOLD!"

Will draw.

See Also

New To Version

0.9.4

2010/09/05 17:27

Upper

Format

upper ( string )

Description

Returns string with all alphabetic characters converted to upper case.

See Also

Example

print upper("BlUe!")

will display

BLUE!

New To Version

0.9.5e

2010/09/05 17:27

Volume

Format

volume level
volume ( level )

Description

Adjust the volume of the notes played with the Sound command. Volume levels must be numeric values from 0 to 10. The default volume is 5.

See Also

New To Version

0.9.5i

2010/09/05 17:27

WAVplay

Format

wavplay filename
wavplay ( filename )

Description

Play WAV audio file asynchronously (in the background).

See Also

New To Version

0.9.4

2010/09/05 17:27

WAVstop

Format

wavstop

Description

Stop playing the current asynchronous (background) WAV audio file.

See Also

New To Version

0.9.4

2010/09/05 17:27
 

Write

Format

write string
write ( string )
write filenumber, string
write ( filenumber, string )

Description

Writes string to the end of an open file. If the file number is not specified file number zero (0) will be used.

See Also

2010/09/05 17:27

Writeline

Format

writeline string
writeline ( string )
writeline filenumber, string
writeline ( filenumber, string )

Description

Writes string append with a newline character to the end of an open file. If the file number is not specified file number zero (0) will be used.

See Also

New To Version

0.9.4

2010/09/05 17:27

Year

Format

year
year ( )

Description

Returns the current system clock's 4 digit year.

See Also

Example

print "today's date is ";
print (month + 1) + "/" + day + "/" + year

will display

today's date is 11/30/2009

New To Version

0.9.4

2010/09/05 17:27
 
fr/singlepage.txt · Last modified: 2010/09/05 17:27 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki