To follow this tutorial series, just copy the code into your FreeBASIC IDE and test it out.
end shuts the game down.
sleep pauses the game and waits for the user to press a key.
print "something" sleep end
This will display something to the screen using print
print 43 print "text" sleep end
Text has to be enclosed in quotes. Numbers do not. Lines of text are known as strings.
print 4 + 2 print 4 - 2 print 4 * 2 print 4 / 2 sleep end
You can perform math on numbers using mathematical operators.
- The plus sign ( + ) is for addition
- The minus sign ( - ) is for subtraction
- The asterisk ( * ) is for multiplication
- The slash ( / ) is for division
print "10" + 10 sleep end
You cannot perform math on strings, only numbers. Note that numbers inside strings count as strings, not numbers.
print "Part 1 " + "Part 2" print "Part 3 " & "Part 4" sleep end
However, you can join together strings with the plus sign ( + ) or the and sign ( & ).
print "The number is" ; 10 sleep end
You can print out multiple chunks of data on the same line using a semicolon.
print "The number is" ; 10 print "The number is" ; print 20 sleep end
If a print statement ends in a semicolon, whatever is displayed by the next print statement will appear on the same line.
someNumber = 10 print someNumber sleep end
Variables store data while the game is running.
someNumber = 10 print someNumber someNumber = 20 print someNumber sleep end
The value contained by the variable can be changed at any time.
someString$ = "This is text." someNumber = 30 print someString$ print someNumber sleep end
The names of variables that contain strings end in a dollar sign ( $ ). Variables that contain integers (whole numbers) do not require a special ending.
someFloat# = 1.01 print someFloat# sleep end
The names of variables that contain floating point numbers (numbers with decimal points) end with the pound sign ( # )
if 2 + 2 = 4 then print "2 + 2 does equal 4!" sleep end
An if statement will execute the code after then if the expression after if is true.
if "someString" = 5 then print "This is never seen because of errors" end if sleep end
You cannot compare a number and a string in an if statement.
for i = 1 to 10 print i next i sleep end
The for-next loop will repeat a block of code a certain number of times.
for i = 1 to 10 step 2 print i next i sleep end
If you add step to a for-next loop, it will skip numbers equal to the number after step.
for i = 10 to 1 print i next i sleep end
Putting a larger number first will not make a for-next loop count backwards.
for i = 10 to 1 step -1 print i next i sleep end
To make a for loop count backwards, you have to make it count backwards.
for i = 1 to 100 if i = 50 then exit for print i next i print "loop over" sleep end
exit for will cause the for loop to end and start at the code after it.