A function is a block of code that works together to accomplish a specific task. This code can be run by using its name. You can usually tell what task a function was created for by its name.
message_to_player("Sorry! You lose!")
If the function is built into the programming language you are using, you will never see the actual code in it.
Arguments / Parameters
An argument (also called ''parameter'') is data (information) given to a function or subroutine. Some functions require arguments, some do not.
For example, if we have a function named change_screen_color(), it needs to know which color you want it use. The color you give this function is a it's argument.
change_screen_color("black")
This code would change the screen color to black. Note that this is a generic example of an argument. The function may or may not exist in your programming language.
Arguments can be strings, numbers, variables, and constants.
Notes
Notes on Game Maker and Basic4GL
Neither Game Maker nor Basic4GL currently allow you to create your own functions. In Game Maker, you must make scripts In Basic4GL, you are stuck with the ancient method of GOSUB and RETURN .
Notes on BASIC vs C
In BASIC based languages, functions and subroutines are usually both included. Usually, the only difference between them is that a function can give you back a value, while a subroutine can't.
In C-syntax languages, subroutines are non-existent and you are expected to use functions instead.
Related Pages
| Categories: Program Flow : Programming |