0051

From GTAMods Wiki
Revision as of 15:07, 1 July 2021 by Seemann (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

GTA III Vice City San Andreas RETURN


Description
Return from the current subroutine.
Syntax
0051: return
Parameter
none

This opcode returns from the current subroutine. When the script encounters a 0051, it will return from where the last 0050 was called.

The game will crash if:

  • 0051 was read before any 0050 was called.

Implementation

See gosub for further details.

/* Note: This is not real code and will not compile. */
/* Based on decompilation of SA v2.0 */

/*
  The game will crash if the call stack is empty
  (i.e. script->callStackPosition == 0), because
  script->callStackPosition - 1 would be -1, and
  therefore an invalid index.

  This can happen if "return" is used outside a
  subroutine.
*/

// Move up to the previous stack frame.
script->callStackPosition = script->callStackPosition - 1;

// Set the current offset to the previous one.
// The previous offset will be the offset of the next instruction after the ''gosub''.
script->readPointer = (&script->callStack)[script->callStackPosition];

Keywords

subroutine, gosub, go sub