COUNTERs (GTA2)
Main Page > GTA2 > Modding Tutorial > COUNTERs
COUNTERs are vital to complex scripts, although they work pretty straightforward. As the name implies, they simply 'count': COUNTERs keep track of values. You can use them to store high values or use them as a simple "on/off switch" for an IF or WHILE.
COUNTER
To use a COUNTER, you'll need to declare one first before LEVELSTART. This can be done with the next command:
COUNTER name
This will create a COUNTER with the value '0'. You can extend the command if you want to give it a different value at the start of the game:
COUNTER name = value
Note that COUNTERs cannot have a value below -32768 or above 32767 and that values must be integer.
SAVED_COUNTER
SAVED_COUNTERs work the same as normal COUNTERs, but their value is stored when the game is saved. Normal COUNTERs will reset when the game is saved and reloaded.
SAVED_COUNTER name = value
SET
To change a COUNTER ingame, you have to use the next command after LEVELSTART:
SET name = new_value
The new value can be a normal number, or one of the following expressions:
SET counter1 = counter2 SET counter1 = ( counter2 + counter3 ) SET counter1 = ( counter2 – counter3 ) SET counter1 = ( counter2 / counter3 ) SET counter1 = ( counter2 * counter3 ) SET counter1 = ( counter2 + value ) SET counter1 = ( counter2 – value ) SET counter1 = ( counter2 / value ) SET counter1 = ( counter2 * value )
Using a COUNTER inside an IF
COUNTERs are often used as the expression for an IF. Using an IF, you can activate a command when a COUNTER reaches a certain value. Often this value is simply '1', which means the COUNTER serves as a on/off switch (in which '1' is on and '0' is off).
COUNTER counter1 COUNTER counter2 = 5 LEVELSTART IF ( counter1 = 1 ) //If counter1 has value 1... SET counter2 = 5 //...give counter2 value 5. ENDIF LEVELEND
You can also use various comparisons with other COUNTERs to use as expression:
IF ( counter1 < value ) //If counter1 is smaller than value IF ( counter1 < counter2 ) //If counter1 is smaller than counter2 IF ( counter1 > value ) //If counter1 is bigger than value IF ( counter1 > counter2 ) //If counter1 is bigger than counter2 IF ( counter1 = value ) //If counter1 is equal to value IF ( counter1 = counter2 ) //If counter1 is equal to counter2
Mapping | Map Editor · Buildings · Roads · Water & animations · Slopes · Flat tiles · Collision info · Level edge · Zones · Putting a level ingame | |
---|---|---|
Scripting | Declarering: | Main script · Script Compiler · Code lists · Commands · Vehicles · Objects · Sounds · Characters |
Programming: | IF · WHILE · COUNTERs · Subroutines · THREAD TRIGGERs · Kill Frenzies | |
Both | Manual · Lighting · Car shops · Cranes & crushers · Gangs · Subway · Multiplayer levels | |
File types | .gci · .gmp · .gxt · .mis · .mmp · .scr · .seq · .tmp · .sty | |
Other | Texting · Physics · Creating vehicles · Terminology · Installing levels |