0050
Revision as of 20:10, 5 February 2012 by Spaceeinstein (talk | contribs) (Created page with "{{Icon|trilogy}} '''GOSUB''' <hr /> <onlyinclude>{{#ifeq:{{{transcludesection|opcode}}}|opcode| '''Description''' : Gosub '''Syntax''' : 0050: gosub [''int''] : gosub [''int''...")
Description
- Gosub
Syntax
- 0050: gosub [int]
- gosub [int]
Parameter
- [int]
- The position in the script it will jump to; can also be a label
This opcode allows the code to jump to a line anywhere in the script. Between that line and a RETURN (0051), this secrion acts like a simple subroutine. The subroutine is independent of the thread that the GOSUB is located. When the code reaches a RETURN, it will jump back to where the GOSUB is located and continues from there. GOSUBs can help dramatically simply repetitive code, and can help make the code cleaner and easier to read for the user.
Examples
The following example, using Sanny Builder, will force a change to the colors of the specified vehicles.
// set constants
const
PRIM_COLOR = 0@
SECD_COLOR = 1@
PLAYER_CAR = 2@
end
while true
wait 10
if
00DD: actor $PLAYER_ACTOR driving_vehicle_type #LINERUN
then
PRIM_COLOR = 0
SECD_COLOR = 1
gosub @SET_COLOR
end
if
00DD: actor $PLAYER_ACTOR driving_vehicle_type #PEREN
then
PRIM_COLOR = 10
SECD_COLOR = 11
gosub @SET_COLOR
end
if
00DD: actor $PLAYER_ACTOR driving_vehicle_type #SENTINEL
then
PRIM_COLOR = 20
SECD_COLOR = 21
gosub @SET_COLOR
end
end
:SET_COLOR
03C0: PLAYER_CAR = actor $PLAYER_ACTOR car
0229: set_car PLAYER_CAR color_to PRIM_COLOR SECD_COLOR
return