Jump to content

BSL:Functions: Difference between revisions

m
(removed instructions on function usage, as this is covered better by BSL:Manual; rewrote legend and gave it its own section; added note on dump_docs)
m (→‎About chr_index: copy-edit)
Line 3: Line 3:


==About chr_index==
==About 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.
"chr_index" is a means of identifying a character in a level, required by some functions like <tt>chr_focus</tt>. Each character including the player-character has a chr_index associated with him/her. Typically the chr_index is determined by the spawn order of the characters. Characters can be spawned either by scripting or by the engine itself (if the character doesn't have the "NotInitiallyPresent" flag in the [[OBD:BINA/OBJC/CHAR|BINACJBOCharacter]] file).


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, if this was run after loading the level with no one spawned except Konoko…
 
For example:
<pre>
<pre>
ai2_spawn Muro
ai2_spawn Muro
Line 14: Line 12:
</pre>
</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.
…then Muro will receive chr_index 1, Mukade will have index 2 and the Bomber index 3. Konoko always has a chr_index of 0 because she's the first character to be spawned. As the game runs, however, things become more complicated. Once a character is deleted, either by being killed (after which the engine deletes them automatically) or by calling <tt>chr_delete</tt> directly, any characters spawned subsequently will fill in the holes left by the deleted characters.


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, if this is done…
 
For example:
<pre>
<pre>
ai2_spawn Muro
ai2_spawn Muro
Line 26: Line 22:
</pre>
</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.
…Mukade will have index 2, but once he's deleted, his index will be freed up. When Bomber is spawned, he will receive index 2 in order to fill the hole left behind. If you are desperate to reset chr_index assignments for the sake of your scripting, you may want to use <tt>ai2_reset</tt>, which resets all characters to the level's initial state.
{{clearall}}


Seems the <tt>chr_index</tt> variables make part of an array in memory, once some variable in the array is cleared, in the next opportunity it is filled up again.
If you want to reset <tt>chr_index</tt> you may want to use <tt>ai2_reset</tt>, which resets all characters to level initial state (take a look at <tt>ai2_reset</tt> implications before using it [[#ai2|here]]).
{{clearall}}
==Legend==
==Legend==
{{Fmbox
{{Fmbox