Skip to content

Data Types

ataylorg edited this page Dec 1, 2017 · 2 revisions

Each primitive type, integer, float, string, boolean, character, byte, is indicated by a name that PixMix uses for declarations.

num A 32-bit, signed, 2’s complement series of digits with a maximum range of 2147483647.
float Follows IEEE 754-2008’s definition of a floating-point number. That is: 1 bit for the sign, 8 bits for the exponent, and 24 bits for the mantissa.
bool A 1 byte value that can store either 1 or 0, or true or false.
char A character is 8-bit (1 byte) data type, capable of holding one character in the local character set.

Primitive Data Types

Integer Types

unsigned char num

Real Number Types

float

Objects

To define an object, use the Object keyword followed by the name of the object. An object may be initialized during instantiation by specifying a list of its member variables and functions within curly brackets.

Object rectangle = {
    num width, height
    fun area() {
        return width * height
    }
}

Arrays

Array elements are indexed beginning at position zero.

Declaring Arrays

You declare an array by specifying the data type as Array, followed by its name. The array can store multiple data types. An example declaration:

Array myArray;

Initializing Arrays

You can initialize the elements in an Array when you declare it by listing the initialized values, separated by commas, in a set of brackets. Here is an example initialization:

Array myArray = [0, “one”, 2, “three”]

Accessing Array Elements

You can access an element in an array by specifying the array name followed by the element index, enclosed in brackets.

myArray[1] = 1

This will assign the value 1 to the second element in the array, at position one.

Multidimensional Arrays

Arrays can contain another array as an element, creating a multidimensional array.

Array a = [[1,2,3], [2,3,4]]

Elements will then be accessed by specifying first the index of the nested array, and second the index of the element within the nested array.

a[1][2]

Would return 4.