Jump to content

BSL:Functions: Difference between revisions

Line 3: Line 3:
Put usage of brackets and commas here. Also tell about the weak syntax (with space as a separator).
Put usage of brackets and commas here. Also tell about the weak syntax (with space as a separator).
===Return value===
===Return value===
When used alone forces the exit from a function. When used with a variable returns that variable.
When used alone forces the exit from a function. When used with a variable it forces the exit from a function and returns that variable.
 
Example (1)
 
<pre>
func void spawnUs () {
    ai2_spawn(Muro);
    sleep(200);
    return;
    ai2_spawn(Barabas);
}
</pre>
 
In this example the code <tt>ai2_spawn(Barabas);</tt> is never executed.
 
Example (2)
 
<pre>
var int current_char_id=0;
 
func int spawnCharacter (string char_name) {
    ai2_spawn(char_name);
    current_char_id=current_char_id+1;
    return current_char;
    dmsg("Hello.");
}
</pre>
 
In this example the current_char is returned from the function (notice the int declaration at the begin of function, which declares the type to return). <tt>dmsg("Hello.");</tt> is never executed.


==Declaration==
==Declaration==
489

edits