Data types

From ZDoom Wiki
Jump to: navigation, search

ACS supports various types of data that you can use. Of these, most are handled as hacks. In reality ACS only supports one data type and that is the integer type.


The integer data type is your basic data type. An integer is any whole number and can be negative, positive or zero. The range for an integer is from -2,147,483,648 to 2,147,483,647. To declare a variable to hold this type you use the int keyword.


ACS has a hacked support for the boolean data type. This data type can hold either a true or false value or a 1 or 0 value. In ACS you use the bool keyword to declare a boolean variable. Even though you use a different name, it is the same thing as an integer and has all the same properties.

//This is legal
bool bTest = 7;


Support for character data type is virtually the same as C/C++ except that you have to use the integer type. When assigning characters to a variable, you have to enclose them in single quotes and would look like this example:

//This assigns a variable to the letter a
int Test = 'a';

You can also make use of the special characters: ASCII NUL '\0', '\\', '\n' for newline and '\t' for a horizontal tab.


In ACS you can define string literals which look like this:

//this is a string literal
"OMG its a string"

When the compiler sees this what it does is add the string to its string table and then assigns an index number to it. The string variable, declared using the str keyword, does not hold the string, but rather, the index to string table, similar to how string literals in C decay into pointers in certain contexts. In other words, the string variable is the same as the integer and has all its properties. The only way that ACS can tell that it is a string is when used by special functions that expect a string.

//This function actually gets passed this strings index in the string table 
//but the function knows to take this number and use it to look up the string table

This is another example on how strings are handled:

//Here we try to add two strings together
str Test = "omg its a " + "string!";
print(s:Test); //This prints "string!" and NOT "omg its a string!"
//what really happened was this
Test = 0 + 1;
//so you see that the index is what is being stored

Fixed point

ACS has a very basic support for fixed point types. What happens is you have to assign them to integer types. The integral part is located in bits 16–31 of the integer and the fractional part is located in bits 0–15.

   3                   2                   1                   0
 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
|          Integral Part        |        Fractional Part        |

To see this in action we have this example:

//This assigns 1.0 to an integer
int Test = 1.0;
//The actual integer value is 65536 as shown by the following command
PrintBold(f:Test); // This prints it as a fixed-point, and will show "1"