This tutorial will introduce you to FreeBASIC using the tried and true "Hello World" method.
Hello World is the first step many programmers take. So, if you are complete beginner, let's get started. Here's the code.
print "Hello World"
sleep
end
Pretty simple, eh? Just three lines of code. Let's go over them one by one.
print displays the text that comes after it onto the screen. In this case, it prints Hello World. When you want to display text to the screen (or window), you need to put the text between double quotes.
sleep tells a FreeBASIC game to wait until the user presses a key. If sleep is not used, then the game will run so fast that it will be over before you barely have a chance to see the window. sleep gives the player a chance to read the text you display before the game ends.
end tells FreeBASIC that the game is over and therefore should shut down the game. You don't have to use it, but, you should. It lets you, FreeBASIC, and other game programmers who look at your code when the game is supposed to end.
Each of these instructions are commonly called commands. This is a holdover from old-style BASIC and is more or less inaccurate. Today, commands are known as functions. In FreeBASIC, something that does something for you, such as display text to the screen, is almost always a function.
What Next?
Did you ace the Hello World Tutorial? We knew you would. Why don't you try a more challenging tutorial. We recommend :
- Identifiers Tutorial - what's in a name?