Difference between revisions of "0AB1"

From GTAMods Wiki
Jump to navigation Jump to search
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<code>0AB1=-1,call_scm_func %1p%</code><br>
+
{{This|For CLEO for GTA III and Vice City prior to v2.0.0.0, use opcode 05F5.}}
'''Description''': Calls a scm function<br>
+
{{Icon|t}} (with [[CLEO]])
'''Parameter 1''': [[Label]] (SCM function start)<br>
+
<hr />
'''Parameter 2''': number of parameters to pass<br>
+
'''Description'''
'''Parameters 3-32''': (optional) Parameters if there are ones<br>
+
: Calls a scm function
'''Supports''': San Andreas (CLEO)<br>
+
'''Syntax'''
 +
: 0AB1: call_scm_func [''label''] [''int''] ( [''any''] … )
 +
'''Parameter'''
 +
: [''label'']
 +
:: [[Label]] (SCM function start)
 +
: [''int'']
 +
:: Number of parameters to pass
 +
: [''any'']
 +
:: Parameters if there are ones (optional), up to 30
  
 
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 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.
  
==Example==
+
== Example ==
 
This is a simple example of the SCM function calculating the square number.
 
This is a simple example of the SCM function calculating the square number.
0@ = 5
+
<syntaxhighlight lang="scm">
0AB1: call_scm_func @GetSQR 1  10 $result
+
0@ = 5
[[004E]]: end_thread
+
0AB1: call_scm_func @GetSQR 1  10 $result
+
004E: end_thread
:GetSQR
+
//…
[[006A]]: 0@ *= 0@
+
:GetSQR
0AB2: ret 1 0@
+
006A: 0@ *= 0@
 +
0AB2: ret 1 0@
 +
</syntaxhighlight>
  
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.
+
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 <span style="color:blue">0@</span> of the current thread equates to 10 (if there would more parameters to pass, the next one will be copied to the <span style="color:blue">1@</span>, then <span style="color:blue">2@</span> and so on). After that the thread jumps to the label <span style="color:green">@GetSQR</span>,. Here the square number is calculated (of a value in the <span style="color:blue">0@</span>). Again, if there would be more parameters, the values of <span style="color:blue">1@</span>, <span style="color:blue">2@</span> etc may be taken in to account, if needed. After the calculation, the game comes to the opcode 0AB2. The value of <span style="color:blue">0@</span> equals to 10*10 = 100 at this moment. Then the following happens: the returned value(s) (<span style="color:blue">0@</span>) 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 <span style="color:blue">$result</span> 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.
 
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.
+
Also pay attention that the local variables are stayed unchanged after the function calling. In this example, the variable <span style="color:blue">0@</span> 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.
  
==Keywords==
+
== Keywords ==
 
CLEO, scm function, call
 
CLEO, scm function, call
  
 +
== External link ==
 +
* {{GTAF|777350|SCM functions (including TraversePoolEntities algorithms)}}, documentation and tutorial by {{U|Wesser}}
 +
 +
[[Category:OpCodes]]
 
[[Category:CLEO Opcodes]]
 
[[Category:CLEO Opcodes]]

Latest revision as of 20:51, 13 January 2019

For CLEO for GTA III and Vice City prior to v2.0.0.0, use opcode 05F5.

GTA III Vice City San Andreas (with CLEO)


Description

Calls a scm function

Syntax

0AB1: call_scm_func [label] [int] ( [any] … )

Parameter

[label]
Label (SCM function start)
[int]
Number of parameters to pass
[any]
Parameters if there are ones (optional), up to 30

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.

Example

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
//…
:GetSQR
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.

Keywords

CLEO, scm function, call

External link