Jump to content

BSL:Functions: Difference between revisions

chr_index information
(chr_index information)
Line 47: Line 47:
** Use "fork" in conjunction with "sleep" to ensure that there is always only one running copy of the function. (Themselves looping functions without sleep can crash the game.)
** Use "fork" in conjunction with "sleep" to ensure that there is always only one running copy of the function. (Themselves looping functions without sleep can crash the game.)
** And remember to design the code so it cannot create two copies of the function running in parallel. When that happens, the desired loop effect is usually broken and "echos" start to apprear.
** And remember to design the code so it cannot create two copies of the function running in parallel. When that happens, the desired loop effect is usually broken and "echos" start to apprear.
==chr_index==
<tt>chr_index</tt> is a variable required by some functions like <tt>chr_focus</tt>. This variable hold a ID for a character and each character have a <tt>chr_index</tt> associated.
Normally the chr_index is associated by the order of the spawn of the characters. The characters can be spawned either by scripting or by the engine itself (if it doesn't have <tt>NotInitiallyPresent</tt> flag at <tt>BINACJBOCharacter</tt> file).
For example:
<pre>
ai2_spawn Muro
ai2_spawn Mukade
ai2_spawn Bomber
</pre>
With the follow code Muro will receive the index 1, Mukade index 2 and Bomber index 3. Konoko always have a <tt>chr_index</tt> of 0, because it's always the first character to be spawned.
This ok, but there's an exception. Once a character is deleted, either by <u>be killed</u> (and the engine delete it automatically) or by <u>calling <tt>chr_delete</tt></u> directly the following characters to be spawned will fill the holes left by the deleted.
For example:
<pre>
ai2_spawn Muro
ai2_spawn Mukade
chr_delete Mukade
ai2_spawn Bomber
</pre>
In this example Mukade have the index 2, but once it's deleted (in this case directly by <tt>chr_delete</tt> function) there will be hole where his id were. When Bomber is spawned, it isn't associated the index 3, but it will be associated the index 2, to fill the hole left behind.
Seems the <tt>chr_index</tt> variable works like in a buffer in memory, once some variable in the buffer is cleared, in the next opportunity it is filled up again.
==Native functions==
==Native functions==
;I DELETED THE VARIABLES FROM THE LIST AND PUT THEM [[BSL:Variables|HERE]]
;I DELETED THE VARIABLES FROM THE LIST AND PUT THEM [[BSL:Variables|HERE]]
489

edits