Using Data Types

   Print  Previous  Next

Primitive Data Types

The example before used two variables with two different data types. Variables offer the possibility to store data. The kind of data depends on the data type. MADRIX Script supports the following primitive data types:

Data Type

Exemplary Values

Description

int

3, -345, 234, 0

32 bit data type. It stores integral numbers between -2 million and +2 million.

float

0.0, -12.45, 3.1415

32 bit data type. It stores floating point numbers.

string

"Hello World", "-3"

Stores character strings of variable length.

bool

true (1), false (0)

Used for implicit use of logical values and comparisons.

Data Type Bool

The data type bool is only used internal and cannot be used to declare a variable. This data type only has to possible values, true or false. It is used for logical operations or for different statements like the if statement. For example, the following expression results in a bool data type and false as its value.

3 > 4

int i = 3 > 4 //results in 0

int i = 3 < 4 //results in 1

 

//usually it is used like this

if(3 > 4)

{

    do something

}

 

True And False

Like said before, a boolean expression results only in true or false.

Furthermore, the keywords true and false are used within MADRIX Script as function parameters or return values. Those parameters or functions are of the type int. In such cases true and false represent 1 and 0, respectively. They can be used in upper case (TRUE / FALSE) and lower case (true / false).

 

Non-Primitive Data Types - Structures

Complex data types, so-called structures, consist of different elements. The elements of a structure are accessed by their names in the following way: nameOfVariable.nameOfElement. For example, col.r, if col is a variable of data type color. The following table is an overview of the structures MADRIX Script provides.

Structure

Elements

Description

color

int r
int g
int b
int w
int a

color stores a color value.

There are 5 channels (red, green, blue, white, alpha) with values between 0 and 255.

 

Example: color c = {255, 255, 0, 0};

Members examples: c.r, c.g, c.b, c.w, c.a

 

»Script Example

date

int day
int weekday
int month
int year

date stores a date.

Values for days include 1 to 31 for a single day of the month.

Values for weekdays include: 0 = Sunday, 1 = Monday, ..., 6 = Saturday.

Values for month include 1 to 12 for every single month of the year.

Vales for year include year dates.

 

Example: date d = {24, 11, 1980};

Members examples: d.day, d.weekday, d.month, d.year

 

»Script Example

time

int hour
int min
int sec

time stores a time.

Valid values are: hours: 0 .. 23, minutes: 0 .. 59, seconds: 0 .. 59.

 

Example: time t = {12, 05, 00};

Members examples: t.hour, t.min, t.sec

 

»Script Example