Variable types

Storing numbers and text

Variables allow you to store numbers and text which can be modified during the course of a script's runtime. Variables are designated by names which can contain any sequence of numbers or letters. The first character of a variable name, however, must always be a specific symbol, otherwise known as that variable's identifier. The maximum length for a variable name is 32 characters. Alambik lets you use five kinds of variables:

• ObjectID,
• Numeric (integer) variables,
• Numeric (floating-point number) variables,
• Text variables (or strings)
• Array variables

Ps : Variable names are limited to 32 chars

Following is a table of the identifiers and ranges for different variable types.

Name Operator Range
String $ No limit
Float ! 1.17494351e-38 to 1.175494351e38
Numeric % -2147483648 to 2147483647
ObjectID @ No limit
Array of ObjectID @ 32*32 elements
Array of numeric % 32*32 elements
Array of float ! 32*32 elements
Array of string $ 32 elements

Variable Types

$ = string

This type of variable contains a sequence or "string" of characters.


$var="your sentence here"

Note: It's possible to concatenate strings of characters using the plus "+" sign.

Example :

for (%i = 1 to 100)
    text.display ("hello"+" world"+str(%i),0,0)

Remarks :

Text variables are the equivalent of two-dimensional arrays. It is thus possible to directly access a specific character in a string using the following technique :

$test= "alambik"
$test[1][2] lets you access the second character in the string ('l').

It's also possible to add text onto a pre-existing string using +=:

$test += "alambik"

this is equivalent to typing:

$test = $test += "alambik"

% = Numeric (integer)

This type of variable contains only whole numbers.


%var=number.random.get (0,255)

Note : Alambik will automatically convert a number into its hexadecimal equivalent if that number is preceded by "0x". For example:

%test = 0xFF

is identical to :

%test = 255

! = float (floating-point number)

This type of variable contains numbers expressed in floating-point notation.


!var=time.get ()

Floating point variables allow the use of numbers with decimal points. They are thus useful for mathematical work as well as for calculating prices.

@ = ObjectID

This type of variable contains an ObjectID (pointer). An ObjectID is essentially a numeric variable which isn't meant to be used for normal runtime operations (like adding, subtracting, etc.). Instead, ObjectIDs are special names which represent Alambik objects and let you manipulate them during a script's runtime.



Every time an instruction takes an ObjectID as a parameter, you can replace the ObjectID parameter value with any instruction that returns the type of ObjectID required.

For example:

Icon.display (Icon.load("dinosaur.png"),0,0)

% = Array

This kind of variable can be used to create a array by using DIM and REDIM instructions.

Array variables can express numbers (%) or text ($). Take, for example, this list of 3 words:

dim ($list[3])
$list[1]= "alambik"
$list[2]= "script"
$list[3]= "language"

An array must, however, always contain variables of the same type (either all %'s or all $'s).

In Alambik it's possible to create one- or two-dimensional arrays for numbers, whereas only one dimensional arrays are permitted for strings.
For example:

dim (%array[8][8]) // possible
dim ($array[8][8]) // impossible

Indeed, strings are already two-dimensional arrays indexed by character location. You can directly access strings as you would any array, as shown below:

$test = "hello world"

$test[1][5] ; access the fifth letter ('o')

Note : By default, the first index of an array is always one.


dim (%array[4]) : To create a 4 lines (1 dimension) array
dim (%array[4][2]) : To create a 4 lines and 2 columns (2 dimensions) array (numbers only).

Redim allows you to scale the dynamic array variables.

Redim (%array[3]) : To scale to 3 lines (1 dimension) the array
Redim (%array[3][1]) : To scale to 3 lines and 1 columns (2 dimensions) the array

Origin allows you to choose the origin of a array:

Dim (%array[4])
Dim (%array2[4])
for (%i = 0 to 3)
    %array2[%i] = %array [%i]

Converting Variable Types

Automatic conversion

int <-> float

To convert a numerical value into text:

String = Text.convert (Number)
String = Str (Number)

To convert a decimal-point number into text :

String = Text.convert (float,"format")
String = Str (float,"format")

Format :

The floating-point decimal number can be displayed according to one of the following format codes:

"" (Full display)
"####.##" (where # represents a digit to display)
"0000.00" (Same as # but 0 will be displayed when there is no digit)
"????.??" (Same as # but a space will be displayed when there is no digit)

For alignment purposes, spaces can placed within these format codes.
For example:

"### ###.##"
"000 000.00"
"??? ???.??"

To convert a number into ASCII:

Char = Text.char.convert (Digit)
Char =Chr (Digit)

To convert text into a number :

Number = Number.convert(String)
Number = Val (String)

Note : Strings can hold both numbers and characters . For example: "2002 Alambik" -> 2002.

To convert a character into a number:

Digit = Number.digit.convert (Char)
Digit =Asc (Char)

To convert an RGB color into a Packed color :

ColorPacked = Number.color.convert (Red, Green, Blue)