From GTAModding
Jump to: navigation, search

0AB1=-1,call_scm_func %1p%
Description: Calls a scm function
Parameter 1: Label (SCM function start)
Parameter 2: number of parameters to pass
Parameters 3-32: (optional) Parameters if there are ones
Supports: San Andreas with CLEO
This opcode calls a SCM function, passes the parameters to it and stores a result to variable(s). The passed parameters values are copied to the local variables in series, then the thread execution is transferred to the label, it executes code there and returns after opcode 0AB2 is executed.


This is a simple example of the SCM function calculating the square number.

 0@ = 5
 0AB1: call_scm_func @GetSQR 1  10 $result
 004E: end_thread
 006A: 0@ *= 0@
 0AB2: ret 1 0@

How it works. First of all, the game comes to the opcode 0AB1. The game reads the number of parameters to pass (1) and its values (10). The variable 0@ of the current thread equates to 10 (if there would more parameters to pass, the next one will be copied to the 1@, then 2@ and so on). After that the thread jumps to the label @GetSQR,. Here the square number is calculated (of a value in the 0@). Again, if there would be more parameters, the values of 1@, 2@ etc may be taken in to account, if needed. After the calculation, the game comes to the opcode 0AB2. The value of 0@ equals to 10*10 = 100 at this moment. Then the following happens: the returned value(s) (0@) is copied to the variable(s) that is written in the opcode 0AB1 which called this function. In our example such variable is $result. After storing of the result, the thread returns back to the 0AB1 and comes to the command end_thread. The value of the $result equals to the 100 (which is square of 10) at this moment. Finally say that 0AB2 could return not only the variables values, but also the number constants. For example, 0AB2: ret 1 1 will forever stores 1 to the result. Also pay attention that the local variables are stayed unchanged after the function calling. In this example, the variable 0@ contains a value of 5 before 0AB1. Despite the fact that this variable was used in the function, after the calling it still equals to 5. This covers on all 32 local variables, so you can freely work with them within a function without fear to lose data.


CLEO, scm function, call

Personal tools