Functions are your friends and you'll be using them as long as you are making games with PlayBasic. This tutorial will introduce you to the basics of using PlayBasic's built-in functions.
Introduction to Functions in PlayBasic Tutorial
The reason most people use PlayBasic, or any other game programming language is because it does things for you that makes game programming faster and easier than if you used a general purpose programming language. 90% of everything you will ever want PlayBasic to do for you is available as functions. Therefore, knowing how to use PlayBasic's built-in functions is very important to making games with it.
A function is like a command that you give PlayBasic. It's like having a faithful dog. If you want your dog to sit, you say "Sit!". Using functions is exactly like this.
Simple Functions
The easiest way to use a function (if the function allows it), is to call the function by name only. You have already seen functions like this in previous tutorials. Sync, WaitKey and End for example.
Sync draws the current frame, WaitKey pauses the game until the user presses a key, and End ends the game. You've already seen all three of them used in the very first beginner tutorial. If you forgot, here's what the code was :
Print "Barkin' Mad PlayBasic"
Sync
WaitKey
End
Arguments
Some functions require arguments (sometimes called parameters). An argument is anything the function needs to know to do it's job. For example, the Print function needs to know what to display. In the code above, you can see that Print is followed by the text we want it display. In this case it's Barkin' Mad PlayBasic. Some functions accept arguments in parenthesis, some do not. If you are unsure, one way to find out is to simply run your code. If it requires parenthesis you will get an error.
Return Values
Functions can also give you something back. This is known as the function's return value. To capture the return value, it is most often stored in a variable.
One of these functions is Rnd(). Rnd() generates a random number between 0 and the number given to it as it's argument. Here's an example :
randomNumber = Rnd(1000)
Print randomNumber
Sync
WaitKey
End
Conclusion
You know know how every function in PlayBasic is used. In later tutorials, you will learn how to make your own functions.