Difference between revisions of "Int keyword"

From Dragon Age Toolset Wiki
Jump to: navigation, search
m
m (Added links)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
The '''int''' type is a signed 32-bit integer between -2,147,483,648 and 2,147,483,647.  The default value is 0.
+
The '''int''' type represents a signed 32-bit integer between -2,147,483,648 and 2,147,483,647.  The default value is 0.
  
 
== Literals ==
 
== Literals ==
  
A literal is a textual representation of a particular value of a type.
+
An int [[Scripting terminology#literal|literal]] can be a decimal (base 10) or hexadecimal (base 16) number. A decimal integer literal consists of a string of decimal digits (0-9). A hexadecimal literal consists of "0x" or "0X" followed by a string of hexadecimal digits (0-9, a-f, A-F).
 
+
An int literal can be decimal (base 10) or hexadecimal (base 16). A decimal integer literal consists of a string of decimal digits (0-9). A hexadecimal literal consists of "0x" or "0X" followed by a string of hexadecimal digits (0-9, a-f, A-F).
+
  
 
== Conversion ==
 
== Conversion ==
Line 33: Line 31:
 
== Persistence ==
 
== Persistence ==
  
The following functions allow an int to exist outside of the scope of the current script by storing it on an object, event or effect:
+
The following functions allow an int to exists outside of the scope of the current script by storing it on an object, effect or event:
 +
 
 +
* [[SetLocalInt]]
 +
* [[SetEffectInteger]]
 +
* [[SetEventInteger]]
 +
 
 +
The following functions allow an int which exist outside of the scope of the current script to be used in the current script by retrieving it from an object, effect or event:
  
 
* [[GetLocalInt]]
 
* [[GetLocalInt]]
* [[GetEventInteger]]
 
 
* [[GetEffectInteger]]
 
* [[GetEffectInteger]]
 +
* [[GetEventInteger]]
  
The following functions allow an int which exist outside of the scope of the current script to be used in the current script by retrieving it from an object, event or effect:
 
 
* [[SetLocalInt]]
 
* [[SetEventInteger]]
 
* [[SetEffectInteger]]
 
   
 
 
== Special ==
 
== Special ==
  
In [[dascript]] there is no Boolean type.  Instead integer values are used to represent Boolean values: 0 represents the '''false''' state and anything else represents the '''true''' state.  For convenience two int constants have been defined in script.ldf to represent the true and false states:
+
In [[dascript]] there is no Boolean type.  Instead integer values are used to represent Boolean values: 0 represents the '''false''' state and anything else represents the '''true''' state.  For convenience two [[boolean constants]] have been defined in [[script.ldf]] to represent the true and false states:
  
 
<dascript>
 
<dascript>
Line 53: Line 51:
 
     int TRUE = 1;
 
     int TRUE = 1;
 
</dascript>
 
</dascript>
 +
 +
Care should be taken when evaluating comparisons with TRUE as, for example, the number 2 will evaluate to '''true''' but 2 == TRUE would evaluate to '''false''' because the literal value of TRUE is not 2.
 
   
 
   
 
== Examples ==
 
== Examples ==
Line 78: Line 78:
  
  
[[Category: DAScript types]]
+
[[Category:Keywords]]

Latest revision as of 14:33, 13 April 2020

The int type represents a signed 32-bit integer between -2,147,483,648 and 2,147,483,647. The default value is 0.

Literals

An int literal can be a decimal (base 10) or hexadecimal (base 16) number. A decimal integer literal consists of a string of decimal digits (0-9). A hexadecimal literal consists of "0x" or "0X" followed by a string of hexadecimal digits (0-9, a-f, A-F).

Conversion

Explicit

The following functions can be used to convert another data type to an int:

The following functions can be used to convert an int to another data type:

Implicit

There is no implicit conversion to an int.

Persistence

The following functions allow an int to exists outside of the scope of the current script by storing it on an object, effect or event:

The following functions allow an int which exist outside of the scope of the current script to be used in the current script by retrieving it from an object, effect or event:

Special

In dascript there is no Boolean type. Instead integer values are used to represent Boolean values: 0 represents the false state and anything else represents the true state. For convenience two boolean constants have been defined in script.ldf to represent the true and false states:

    int FALSE = 0;
    int TRUE = 1;

Care should be taken when evaluating comparisons with TRUE as, for example, the number 2 will evaluate to true but 2 == TRUE would evaluate to false because the literal value of TRUE is not 2.

Examples

void main()
{
    // uninitialised: value = 0
    int nDefault;
 
    // initialised: value = 42
    int nSpecific = 42;
 
    // initialised with hexadecimal literal: value = 42
    int nHexadecimal = 0x002A;
 
    // initialised with boolean constant: value = 1
    int bBoolean = TRUE;
}

See Also

PrintInteger