Difference between revisions of "0AB1"
m |
|||
(One intermediate revision by one other user not shown) | |||
Line 5: | Line 5: | ||
: Calls a scm function | : Calls a scm function | ||
'''Syntax''' | '''Syntax''' | ||
− | : 0AB1: call_scm_func [''label''] [''int''] ( [''any''] | + | : 0AB1: call_scm_func [''label''] [''int''] ( [''any''] … ) |
'''Parameter''' | '''Parameter''' | ||
: [''label''] | : [''label''] | ||
Line 22: | Line 22: | ||
0AB1: call_scm_func @GetSQR 1 10 $result | 0AB1: call_scm_func @GetSQR 1 10 $result | ||
004E: end_thread | 004E: end_thread | ||
− | // | + | //… |
:GetSQR | :GetSQR | ||
006A: 0@ *= 0@ | 006A: 0@ *= 0@ | ||
Line 38: | Line 38: | ||
* {{GTAF|777350|SCM functions (including TraversePoolEntities algorithms)}}, documentation and tutorial by {{U|Wesser}} | * {{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
(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
- GTAForums: SCM functions (including TraversePoolEntities algorithms), documentation and tutorial by Wesser