Now that the characters themselves are stored as strings. In other programming languages(categorically speaking non-GTA), most often, a variable of type string does not hold an entire set of letters. This variable is stored in a memory address where the letters are. String variable represents in fact a pointer to the first character string, and is, like any other pointer, 4 bytes. No matter what length of the string - 1 letter, or 500, string variable is always 4 bytes in length (in most cases).
In San Andreas strings themselves are stored in variables. As we know, there are 2 kinds of variables - local's & global's. For each of them in the memory have a certain memory area of limited size. For example, for each stream selected foreground appears 32 to 4 bytes and, consequently, the buffer memory to store the values of these variables in 128 bytes. A similar situation with a buffer of global variables (the size may vary in when compiling).
Strings are stored within the buffer variables. This means that the variable string 0@s is not a pointer to the record the first letter of the word 'MAIN', but these are characters (ASCII-code).
Let us now move on to the two types of strings - short and long (variable-length strings).
Short strings are always held in the memory of 8 bytes. In such a variable it can store up to 7 characters, inclusive, the balance is filled with zeros. It does not matter 1 letter in a row and 7, the size of a string is always 8 bytes. Thus, if you type in the variable '1@s' string 'STRING', it takes 8 bytes. Given that the letter strings are stored in the variables themselves (as explained above) and a variable can only store 4 bytes (1 letter - 1 byte), then the string will be recorded in the following order of variables: 2@.
1@ stores 'STRI', and 2@ stores 'NG'. (total = 'STRING')
With long strings it's a similar situation, with the only difference being that - they took the 4 variables (16 bytes).
1@v = "LONG_STRING" => 1@ = "LONG", 2@ = "_STR", 3@ "ING", 4@ - Keep balance (zero bytes).
Note 1@v = "MAIN" and even holds only 4 characters, but the record of such a variables values are not only 1 but 2 @ @, 3@ and 4@
16 bytes is the limit for string's variables. You can not write to a variable 1@v string length of 20 characters, as a example(it must be 16 or lower).
If you summarize, the line held in the memory of either 8 or 16 bytes (depending on the type of the string). They want to store 2 or 4 variables that are in a row (0@, 1@, $1, $2, etc...).
Now we proceed to the main. As new waves created opcode 004F, you can send numeric parameters, whose values are recorded on a new flow of local variables. (In other words new data.)
create_thread @THD 100 $ONMISSION 1@
in the stream @ the new variable 0@ is equal to 100, the value 1@ $ONMISSION, 2@ 1@ is equal to the value stream, which was caused by opcode 004F(create_thread).
And the same rule also apply's when using SCM-functions(call_scm_func):
0AB1: call_scm_func @Recalculate 1 -1.0
function Recalculate 0@ variable will be equal to -1.0.
But the standard way to convert is not the number but the string in the flow function can not be.
0AB1: call_scm_func @EndThread 1 'NAME'
('NAME' meaning the name of the thread to end.)
But there is another way. Recall that the string is stored in variables. The line - a collection of letters, which are in fact numbers. We can save the string in a variable string and send it by parts, like this:
0@s = 'NAME'
0AB1: call_scm_func @EndThread 2 0@ 1@
... and functions use the line through string variables:
0459: end_thread_named 0@s
0AB2: ret 0
For long string is similar, but we must send a value of 4 variables:
0@v = "SNEAKERBINCBLK" // 0@..3@
4@v = "SNEAKER" // 4@..7@
8@ = 3
0AB1: call_scm_func @SetClothes 9 0@ 1@ 2@ 3@ 4@ 5@ 6@ 7@ 8@ // pass 2 strings
And so you can set the function, then return from the main.scm function using the brother opcode of 00b1, (0AB2: ret 0) - this opcode is required when using opcode 00b1.
087B: set_player $PLAYER_CHAR clothes_texture 0@v model 4@v body_part 8@
0AB2: ret 0
Perhaps to fully understand this clearly you will need a bit of experience in programming as well as imagination. It is important to understand the principles of storing strings in memory, if you do, it all becomes very clear.
- Questions can be asked in this topic.
- For questions about using SCM-functions, please, create your own topic regarding help.
- Questions of memory handling can be posted in the SA Memory Example Topic.
- San Andreas Strings
- Passing Strings To A New Thread by Seemann.