Jump to content

BSL:Tutorial/Scratch: Difference between revisions

Line 267: Line 267:




== Part 8: Forking and Separate Functions==


This is the part where we start moving commands out of "main". Create a new function called "logic" like this : type "func logic" two lines below the '''}''' of "main". Type '''{''' nad copy out everything inside "main" into "logic". Type <tt>fork logic</tt> in main. It should look like this :
<tt>func void main(void)<br>
{<br>
fork logic<br>
}<br>
<br>
func logic<br>
{<br>
...<br>
}</tt>
... being whatever you had in "main" before. Add <tt>chr_wait_health griffin 0</tt> at the end of "logic", then type <tt>fork logic2</tt>. Create the function "logic2". In "logic2" you can write whatever you want that you have learned before. For the prupose of this example, '''...''' will represent whatever you had, '''..''' will represent whatever you want, and typed text will represent thing that must be included.
<tt>func void main(void)<br>
{<br>
fork logic<br>
}<br>
<br>
func logic<br>
{<br>
...<br>
chr_wait_health griffin 0<br>
fork logic2<br>
}<br>
<br>
func logic2 {<br>
..<br>
}<br>
===Extra: Multiple Forking===
More than one function can be forked in the same function. Look at ths example :
<tt>func void main(void)<br>
{<br>
fork logicA<br>
fork logicB<br>
}<br>
func logicA {<br>
..<br>
}<br>
func logicB {<br>
..<br>}</tt>
Both "logicA" and "logicB" are executed at the same time. If <tt>chr_wait_health griffin 0</tt> were to be removed, likewise, both "logic" and "logic2" are executed at the same time.
== Part 9: Variables and Save Points ==
Every wondered why there is no folder for basic training? The truth is, it is actually part of the Warehouse level and is managed by save points.
This is the beginning of the "level_start" which is forked from "main" in the original level scripts.
<tt>func void level_start(string ai_name)<br>
{<br>
<br>
    my_save_point = save_point;<br>
<br>
    if (my_save_point eq 0)<br>
    {    <br>
        ...<br>
    }<br>
<br>
    if (my_save_point eq 1)<br>
    {<br>
        ...<br>
    }<br>
<br>
    if (my_save_point eq 2)<br>
    {<br>
        ...<br>
    }<br>
<br>
    if (my_save_point eq 3)<br>
    {<br>
        ...<br>
    }<br>
<br>
    if (my_save_point eq 4)<br>
    {<br>
        ...<br>
    }<br>
<br>
    if (my_save_point eq 5)<br>
    {<br>
        ...<br>
    }<br>
}</tt>




85

edits