Sanny Builder
In English
In English
  • Introduction
  • Credits
  • Version History
  • Language
    • Data Types
      • Constants
      • Variables
      • Arrays
    • Instructions
      • Opcodes
      • Keywords
      • Classes
      • Expressions
      • Built-in Commands
      • HEX..END
    • Control Flow
      • Labels
      • Conditions
      • Loops
      • Switch
    • Functions
    • Import/Export
    • Directives
    • Comments
  • Edit Modes
    • CustomLabels.ini
    • Code Templates
    • Enums.txt
    • Extensions
    • Opcodes List (SCM.INI)
  • Editor
    • Features
    • Options
      • General
      • Formats
      • Editor
      • Theme Editor
      • Hotkeys
      • Debugger
      • Edit modes
    • Console
    • Hotkeys
    • Opcode Search Tool
    • Command Line Interface
    • Language Service
    • SCM Debugger
  • SCM Documentation
    • GTA Limits
    • GTA III
      • Ped Types
      • Radar Icons
    • Vice City
      • Button IDs
      • Gang IDs
      • Garage IDs
      • Interiors
      • Ped Types
      • Radar Icons
      • Weapon IDs
    • San Andreas
      • Button IDs
      • Gang IDs
      • Garage IDs
      • Haircuts
      • Interiors
      • Particle Effects
      • Ped Types
      • Player Clothes
      • Player Body Parts
      • Special Actors
      • Statistics ID
      • Tattoos
      • Train Types
      • Vehicle Variations
      • Weapon IDs
      • Weather IDs
      • Zones
    • Liberty City Stories
      • Gang IDs
      • Model IDs
      • Player Clothes
      • Special Actors
      • Weapon IDs
      • Weather IDs
    • Vice City Stories
      • Gang IDs
      • Player Clothes
      • Weather IDs
  • Troubleshooting
    • Error Messages
      • 0001: INI file not found
      • 0002: Unknown array type
      • 0003: Error reading script.img
      • 0004: Unknown parameter type
      • 0005: Invalid edit mode
      • 0006: Unknown file header
      • 0007: File not found
      • 0008: Error reading opcodes list
      • 0009: Opcodes list not found
      • 0010: Unknown opcode
      • 0011: Unknown opcode
      • 0012: Incorrect jump instruction
      • 0013: Unknown directive
      • 0014: Incorrect expression
      • 0016: Script not found
      • 0017: Unknown type of variable
      • 0018: Invalid array size
      • 0019: Unknown array type
      • 0020: Variable is not declared as array
      • 0021: Incorrect variable name
      • 0022: Loop counter is not a variable
      • 0023: Unexpected instruction
      • 0024: Error reading integer number
      • 0025: Incorrect counter range
      • 0026: Error reading floating-point number
      • 0027: String is too long
      • 0028: Unterminated string
      • 0029: Invalid debug script ID
      • 0031: Invalid total number of elements
      • 0032: Invalid value in the header
      • 0033: Invalid local variable name
      • 0034: Local variable is out of range
      • 0035: Expected word
      • 0036: Local mission variable is out of range
      • 0037: Debug script not found
      • 0038: Unknown type of array
      • 0039: Invalid element definition
      • 0040: Constant name or value not found
      • 0041: Invalid mission id
      • 0042: Duplicate external script name
      • 0043: Invalid array index
      • 0044: Invalid array name
      • 0045: Invalid array syntax: variable name is missing
      • 0046: Invalid array syntax
      • 0047: Invalid array size
      • 0048: Error reading array size
      • 0049: Not enough parameters for opcode
      • 0050: Not enough parameters for command
      • 0051: Error writing script.img header
      • 0052: Error writing script.img
      • 0053: Recursive include
      • 0054: Label not found
      • 0055: Identifier not found
      • 0056: Label redeclared
      • 0057: Internal label not found
      • 0058: Invalid parameter
      • 0059: Invalid opcode definition
      • 0060: No input file
      • 0061: Empty source
      • 0062: IDE file not found
      • 0063: Mission label expected
      • 0064: Mission label not found
      • 0065: External script label not found
      • 0067: Forbidden character in external script name
      • 0068: Forbidden character in identifier
      • 0069: Forbidden character in object name
      • 0071: Incorrect number of conditions
      • 0072: Missing logical operator
      • 0073: Redundant logical operator
      • 0074: Disabled option
      • 0075: Incorrect hexadecimal value
      • 0076: Condition expected
      • 0079: Invalid parameter in Alloc command
      • 0080: Non-negative integer number expected
      • 0081: Too many actual parameters
      • 0082: Invalid syntax
      • 0083: Unknown model ID
      • 0084: Jump to offset 0
      • 0086: Invalid array index
      • 0087: Invalid variable
      • 0088: Global variable is out of range
      • 0089: Opcode not found
      • 0090: Duplicate constant
      • 0091: Not enough memory to allocate a local variable
      • 0092: Incorrect export symbol
      • 0093: Only headless scripts can export code
      • 0094: Duplicate export name
      • 0095: Incorrect import name
      • 0096: Incorrect import path
      • 0097: Too many actual parameters
      • 0098: Unknown operator
      • 0099: Left-hand side of the assignment must be a variable
      • 0100: Invalid operator
      • 0101: Variable is not a class instance
      • 0102: Switch statement needs a variable
      • 0103: Expected a switch case
      • 0104: Expected a value for the switch case
      • 0105: Expected a function argument name
      • 0106: Expected a function argument type
      • 0107: Expected function return type
      • 0108: Unsupported argument type
      • 0109: Expected variables to store function result
      • 0110: Function must return N values
      • 0111: Function not found in current scope
      • 0113: Duplicate function declaration
      • 0115: Invalid variable name. Name is reserved by another class or function
      • 0116: Invalid variable name
      • 0117: Invalid function name
      • 0118: Unexpected value to return
      • 0119: Unsupported type of argument
      • 0120: Expected calling convention type
      • 0121: Expected function's static address
      • 0122: A non-static function can't be called by name
      • 0123: A 'thiscall' function requires a pointer
      • 0124: Foreign functions can't return more than one value
      • 0125: Unexpected return type in function
      • 0126: Can't export a foreign function definition
      • 0127: Unexpected mission label in function
Powered by GitBook
On this page
  • Global variables
  • Saved Variables
  • DMA Variables
  • Local variables
  • Timer Variables
  • String Variables
  • Declaring a variable type
  • Variable Initialization
  1. Language
  2. Data Types

Variables

A variable (var) is a named storage location that contains a value and can be read/rewrite many times. Variables can be either global or local.

Global variables

A global variable starts with $ followed by any combination of letters, digits and _:

$variable1 $100 $____

Their values are available from any place of the code.

Saved Variables

A saved variable is a special global variable available only in LCS and VCS modes. Its name is prefixed with $_, e.g., $_var. The value of this variable persists across saved games. Global variables denoted by $ only (e.g., $var) are not saved and they get blank values when the LCS or VCS game loads.

DMA Variables

When global variables are compiled, they get assigned a unique numeric index in the global variable space. The runtime then uses this index to access the variable.

If variable's name is already numeric, the compiler uses it as is. For example, $100 has the same index regardless of other variables. $var, on the other hand, can be compiled with different index each time, depending on slots availability. Some authors refer to such variables as DMA-variables (Direct Memory Address).

Another form of global variables is ADMA (Advanced Direct Memory Access). ADMA-variables can read from and write into the main.scm bytecode.

$myVar = &0 // read DWORD value from offset 0 of main.scm into $myVar
&120 = 5 // write DWORD value 5 into offset 120 of main.scm 
&57 += &120(&231,4i) // can also be used as an array element

ADMA variables don't affect the size of the global variable space in the main.scm header.

Local variables

Local variables can be created using the following syntax:

<type> <variable name>
int a
float distance
string name

a = 1
distance = 15.5
name = 'CJ'

An initial value can follow the variable name to reduce the number of the lines of code:

int a = 1
float distance = 15.5
string name = 'CJ'
<local var index>@

For example, 0@, 999@, 56@.

Timer Variables

Each script or a mission have 2 special local variables called TIMERA and TIMERB. The value of a timer variable is increased automatically when the game clock advances, so they are commonly used to measure time elapsed since the timer reset:

0006: TIMERA = 0 // reset the timer

:WAIT_2S
0001: wait 0 ms
00D6: if
0019:   TIMERA > 2000 // if the timer value is > 2000, i.e. 2 seconds has passed
004D: jump_if_false @WAIT_2S
0662: printstring "2 seconds has passed" // display the message

TIMERA and TIMERB names are only available starting with Sanny Builder v3.3.0. In older scripts the timers are known as 16@, 17@ (GTA3, VC) or 32@, 33@ (SA).

String Variables

A global variable containing a short string literal starts with s$.

05A9: s$MyString = 'GLOBAL'

A local variable containing a short string literal ends with@s.

05AA: 1@s = 'LOCAL'

A global variable containing a long string literal starts with v$.

06D1: v$MyString = "LONG_GLOBAL"

A local variable containing a long string literal ends with@v.

06D2: 1@v = "LONG_LOCAL"

Declaring a variable type

Variables are commonly used in the expressions. If the right operand is a number constant, the opcode can be omitted:

$var = 0
$myarray($index, 10i) >= 150

If both operands in the expression are variables, the compiler cannot determine the correct opcode, because the types of the variables are unknown.

For example, there are two opcodes to increment a variable value: 0058 for integer values and 0059 for floating-point values.

0058: $Var1 += $Var2 // (int)
0059: $Var1 += $Var2 // (float)

Assuming there is no opcode, which one to use?

$Var1 += $Var2 // ??

To tell the compiler the type of the variable, use the var keyword.

var <variable>: <type>

A variable is a valid global or local variable name as described above.

A type could be one of these:

  • Integer, Int - integer values

  • Float - floating-points values

  • String, ShortString - a variable containing a string literal with the fixed length (only for the arrays, use s$, @s for variables)

  • LongString - a variable containing a string literal with the variable length (only for the arrays, use v$, @v for variables)

Example:

var $size: integer

You can define types for multiple variables by separating each declaration with a comma like this:

var $x: float, $y: float, $z: float

If you prefer to have each declaration on its own line, conclude them in a VAR..END construct:

var
   $x: float
   $y: float
   $z: float
end

When variable types are known, the compiler is able to process the expression without opcode:

var $Var1: Integer, $Var2: Integer

$Var1 += $Var2 // opcode 0058

Once the type of the variable is declared it is used for all the code following the declaration. You can re-declare variables to set the new type:

script_name 'Food'
var
    10@ : Float
    $Var : Float
end
$var = 1
10@ = $Var
end_thread

thread 'Loop'
var
    10@ : Int
    $Var : Int
end
$var = 1
10@ = $Var
end_thread

In the 'Food' script 10@ is the floating-point variable. In the 'Loop' script 10@ is the integer variable.

You can re-declare variables as many times as you need.

Variable Initialization

You can specify an initial value for the variable when declaring it. Write = and then the value:

var $fVar: float = 1.0

or

float $fVar = 1.0

The variable $fVar is now declared as Float and the compiler adds the opcode 0005 in the script:

0005: $fVar = 1.0

Initialization is allowed for variables, but not for arrays.

PreviousConstantsNextArrays

Last updated 1 year ago

Each script has a number of local variables. As the name implies, their values are available only within the current script or the mission.

Due to this feature is only available in CLEO scripts. In SCM scripts local variables can be referenced using legacy syntax:

<Class name> - any available

limited
design limitations
class name