PetitBasic Manual

(Note : this manual is a translated version of the original French. If you see any mistake please contact me.)

This manual will make you understand how to use PetitBasic.

I'll consider that you know programing's basics.

Summary

Introduction Conditional Structures Loops Subs System's Variables and Commands Functions Commands Search

Introduction

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean scelerisque tellus metus, vel consectetur lacus suscipit eu. Aliquam sed sodales nisi. Nunc laoreet finibus neque, ac faucibus justo consectetur vitae. Ut maximus metus ac dictum varius. Nam suscipit eros vitae nibh lobortis, eget lobortis metus porta. Ut sed vehicula tortor. Vestibulum id feugiat lectus. Vivamus eu placerat leo. Sed accumsan auctor nisi. Pellentesque vitae tortor hendrerit, faucibus nunc nec, venenatis massa. Cras vehicula eros lectus, et sodales erat interdum in. Phasellus tristique ipsum eget lacus congue fermentum. Aenean lorem mi, imperdiet vitae ullamcorper ut, luctus a magna. Pellentesque volutpat ex quis ex vehicula, sed gravida risus tempor. Proin commodo orci eu pellentesque condimentum.

Conditional Structures

IF block

Conditional structures represent a set of commands which will be executed when a certain condition is validated.

on PetitBasic, they appears as IF blocks. These blocks have at least two commands : if and ifend.

if [condition]
[commands]
ifend

You can also add two optionnal commands : elseif and else.

if [condition]
[commands]
elseif [condition]
[commands]
else
[commands]
ifend

You can add any number of elseif, the same way you can nest IF blocks onto another IF blocks.

Conditions

PetitBasic handles conditions simply : if the expression is equal to 1 or "true" (note that he accepts strings "true" and "false"), it'll be considered as validated.

Let's see now condition's operators : here's the basics operators : =, <, >, <=, >= and <>.

You'll easily recognize some of these, and for some precision <> means inequality.

Add to this some boolean operators, "And", "Or" and "Not".

Loops

FOR loops

FOR loops are loops (obviously) who execute code a defined number of times.

Here's the PetitBasic Syntax :

for [variable] = [begin] to [end] {step [step]}
[commands]
next

All commands in the FOR loop will be executed while the value of variable hasn't reached the end value. The variable will be automatically incremented by one at each loop. This value can be changed if you have specified a step.

WHILE loops

WHILE loops, are loops whose number of iterations is not determined in advance.

while [condition]
[commands]
wend

While the condition is true, we'll run code indefinitely inside of it. If the condition is false before enter the loop, we'll ignore it without entering.

Subs

Subs are groups of code lines that can be called anywhere in your program. Here's the PetitBasic syntax :

sub [sub name]
[commands]
subend

Commands in the sub will not be executed : you need to call it in your main program if you want to execute it. You can create subs anywhere in your program, but you should put them at the beginning and the end of your main program.

When you want to execute your sub, you can call it with the GOSUB command :

gosub [sub name]

Keep in mind that subs and main program's variables are the same.

System's Variables and Commands

Prototype Description
EVT Refresh the window and manage all system events. (e.g. when the user clicked on the cross for close the window)

Functions

Prototype Description
var = ABS( val ) Return the absolute value of val. If val is negative, return it in positive value.
Prototype Description
int = ASC( char ) Retrun the decimal value of character char.
string = RGB( red, green, blue ) For red,green and blue between 0 and 255, returns the hexadecimal color value, formatted like HTML color code "#RRGGBB".

Commands

Prototype Description
LOAD "ResourceType:FileName" Loads the file as specified resource. For now ResourceType can only be CHR.
Resources Types :
- CHR : on-screen Character set.
DEBUG bool (default: enabled) If bool is equal to 1, when the program get an error, he'll wrote in 'report.txt' all his variables.
Prototype Description
CLS Clear the screen with actual colors.
COLOR foreground, background For each argument between 0 and 15, or if this is a HTML color code like the RGB function gives or directly a string with color name.
Change text foreground and background color.
0 -> "TRANSPARENT", 1 -> "DARKGRAY", 2 -> "RED", 3 -> "PINK", 4 -> "BLUE", 5 -> "PURPLE",
6 -> "CYAN", 7 -> "BROWN", 8 -> "ORANGE", 9 -> "BEIGE", 10 -> "DARKGREEN", 11 -> "GREEN",
12 -> "YELLOW", 13 -> "GRAY", 14 -> "BLACK", 15 -> "WHITE"
LOCATE x, y Change the cursor position to (x,y)
PRINT val1 [, val2, val3 ... ] Displays from the cursor all the contents of each parameter values by concatenating them together. Moves the cursor at the next line.
TRANSPARENT bool If bool is equal to 1, enables the transparent color. You can obtain this color with RGB(254,254,254), #FEFEFE in HTML code or simply the parameter 0 of COLOR