Lesson 8: Input, Parameters, and Arguments
Lesson 8: How Input, Parameters, and Arguments Work
Input is information added to a program and used by code to make changes.
Input is information added to a program and used by code to make changes.
The function examples given in the previous lesson didn’t need any input:
GetNumberOfMousetrapsYouCanAfford() : int
Copy full snippet
You know this because the parentheses () in the function signature above are empty.
Parameters
You can define the input a function needs by adding a parameter to the function signature.
A parameter is a constant that’s declared in the function signature between the parentheses. When a parameter is set, you can use it in the body of the function.
The syntax for a function that includes a parameter looks like this:
| | name(parameter : type) : type = |
| --- | --- |
| | codeblock |
Copy full snippet
In the following example, CoinsPerMousetrap is now a parameter for the function BuyMousetrap():
| | var Coins : int = 500 |
| --- | --- |
| | |
| | BuyMousetrap(CoinsPerMousetrap : int) : void = |
| | set Coins = Coins - CoinsPerMousetrap |
| | Print("Mousetrap bought! You have {Coins} coins left.") |
You're reading a preview
The full reference is free for BrainDeadGuild Discord members — sign in to read it all, or open the original at the source.
Sign in with your BrainDead.TV / BrainDeadGuild Discord account for full access.