Main Page > GTA2 > Modding Tutorial > IF
IF is used to activate commands when a certain situation occurs. Simply put, IF is "If X occurs, do Y". You can let the script wait for the player to enter a car to show a message, for example.
IF is used as followed:
IF ( expression ) //command ENDIF
expression | The situation that triggers the commands between IF and ENDIF. It must be a valid expression, which can be a COUNTER or a check like HAS_CHARACTER_DIED. A list of checks can be found in GTA2 Scripting.doc. |
---|---|
command | The commands that have to be triggered by the situation. It can be any number of commands. |
ENDIF | Every IF must end with an ENDIF. |
Variables
IF can be used in all sorts of ways. For example, it is possible to create another IF within an IF:
IF ( situation1 ) //These commands are triggered when situation1 occurs. IF ( situation2 ) //These commands are triggered when situation1 and 2 occur. ENDIF ENDIF
Note that the second IF is indented. This isn't necessary, but makes it easier to read. Also, note that both IFs have their own ENDIF.
You can also add more checks:
IF ( NOT ( situation ) ) //These commands are triggered when the situation does not occur. ENDIF
IF ( situation ) //These commands are triggered when the situation occurs. ELSE //These commands are triggered when the situation does not occur. ENDIF
IF ( ( situation1 ) AND ( situation2 ) ) //These commands are triggered when situation1 and 2 occur. ENDIF
IF ( ( ( situation1 ) AND ( situation2 ) ) AND ( situation3 ) ) //These commands are triggered when situation1, 2 and 3 occur. ENDIF
IF ( ( situation1 ) OR ( situation2 ) ) //These commands are triggered when situation1 or 2 occur. ENDIF
IF ( ( ( situation1 ) AND ( situation2 ) ) OR ( situation3 ) ) //These commands are triggered when situation1 and 2, or only 3 occurs. ENDIF
There are many more configurations possible. Pay close attention to the placement of the brackets: there must be an )-bracket for every (-bracket and it's only possible to combine two situations at a time.
So this is wrong:
IF ( ( situation1 ) AND ( situation2 ) AND ( situation3 ) )
But this is right:
IF ( ( ( situation1 ) AND ( situation2 ) ) AND ( situation3 ) )
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 |
Read in another language
This page is available in 1 language