18,700
edits
(tried to order sections more logically; placed section on built-in commands higher and tried to explain them a little better; various wording tweaks) |
(→Functions: brought in some elaboration on function signatures and calling from BSL:Functions) |
||
Line 561: | Line 561: | ||
} | } | ||
The input which the function accepts is listed between the parentheses | This line is known as the function signature. The type of the function comes after the "func" keyword, in this case "int", which means it can return a value of type "int". The input which the function accepts is listed between the parentheses and separated by commas. First the type of the input is given ("int" in the first case), then the name of that input is given; this name will be used within the function to refer to that input but has no meaning outside of it. These inputs are known as "parameters" or "arguments". BSL functions cannot accept more than eight parameters. | ||
====void==== | ====void==== | ||
Functions do not need to accept or return data. When they don't, you use "void" to indicate this. Note that both "void"s can be omitted and will be assumed implicitly. | Functions do not need to accept or return data. When they don't, you use "void" to indicate this. Note that both "void"s can be omitted and will be assumed implicitly. | ||
func void func_start(string ai_name) # | func void func_start(string ai_name) # returns nothing to calling function, but accepts a string | ||
{ | { | ||
... | ... | ||
} | } | ||
func void music_force_stop(void) # | func void music_force_stop(void) # neither returns nor accepts any data | ||
{ | { | ||
... | ... | ||
} | } | ||
func music_force_stop # | func music_force_stop # same signature as previous function | ||
{ | { | ||
... | ... | ||
Line 582: | Line 582: | ||
===Calling=== | ===Calling=== | ||
When you call a function it will execute its statements from top to bottom or until it hits a "[[#Returning|return]]" statement. This means that when you call a second function from inside another function, the second function will be executed until its end and then the rest of the first function will be executed. | |||
You do not use "func" when calling a function. You simply use its name: | You do not use "func" when calling a function. You simply use its name: | ||