[Edit] As pointed out by a forum member, I have refered to an older version of Freebasic, 2.0 is not the latest version, I will update this tutorial when and if I get time, if anyone has any difficulty following this tut, post it here, please dont PM me about it, I have my hands full at the moment ... This goes for every other post on this forum, it is impossible to maintain and update them all because there are over 50,000 posts, if anyone has a problem, post it in the thread and you can get help that way. thanks.[/edit]
Part 1:
How to install Freebasic 2.0 with fbedit, tinyptc ext++ and ufmod.This is a beginners guide to getting Freebasic actually installed on your computer ready for action!
The series of simple tutorials that will follow this will talk you through some simple concepts and end up with you making some nice things.
Freebasic sadly hasn't been updated for a while but it is still a really great language for you to learn with. In fact, many of the things you see in todays demos can all be achieved with a little bit of thought in Freebasic.
The things we need to use Freebasic 2.0 , tinyptc_ext++ and ufmod are:
- The Freebasic Binaries.
- A Code Editor.
- Tinyptc_ext++
Step 1:So let's download the stuff we will need.
Please download all this stuff to your desktop, just download it, don't extract anything yet!
First of all we'll leech freebasic..Download this;
FREEBASIC 2.0 (http://sourceforge.net/projects/fbc/files/Binaries%20-%20Windows/FreeBASIC-v0.20.0b-win32.exe/download)
Next we need to leech Fbedit (a pretty nice code editor as it goes):FBEDIT (http://radasm.110mb.com/Upload/FbEdit.zip)
Next we need to grab Tinyptc_Ext and ufmod extension from;TINYPTC EXT++ (http://www.dbfinteractive.com/forum/index.php/topic,3806.0.html)
Please note that you have to be logged into your account to download it. You will find the file attached to the bottom of the first post.
Step 2:Installing Freebasic 2.0
- Look on the desktop. There is a white circular icon with a drawing of a horse on it.
- Double click this to start the installation process.
- After you have agreed to the agreement etc you will come to a box that allows you to choose your destination folder, make a note of where it is going and just click next to continue the setup.
- Please wait while the files extract themselves into the right places.
Step 3:Installing FBEDIT
- The Fbedit file is in a zip file on your desktop.
- Click on it with the *right mouse button* and choose the option that says:
Extract to Fbedit/ .. Allow it to extract the files. - A directory called FbEdit will have been created on your desktop.
- Go into that directory and inside it you will find a file called Fbedit.exe this is what you need to click to launch Fbedit, double click it to set it up.
- A prompt will come up to ask you to specify the locations for freebasic.
- You can safely leave the project path as it is.
- The compiler path should point at the directory you made a note of when installing freebasic
- The help path should be the same with \Help at the end
Step 4:Installing PTC_EXT and ufmod..
- Right click on the archive called Tinyptc_ext++ and extract to Tinyptc_ext++
- You need to cut the two files;
libmmx.a
libtinyptc_ext++.a
and paste them into the lib\win32 folder of your freebasic installation, the path probably looks similar to this:
C:\Program Files\FreeBASIC\lib\win32
- Go back to the desktop into the directory that was created when you extracted tinyptc_ext++
Cut the file;
tinyptcx_ext++.bi
and paste it into the inc folder of your freebasic installation. The path looks something like this;
C:\Program Files\FreeBASIC\inc
[/i]
[/list]
Once it's installed in there you have FREEBASIC 2.0, FBEDIT, TINYPTC_EXT and UFMOD all installed so you will be ready to start working through the code examples that follow this post.
Congratulations, you're ready to start coding!
The next posts that follow this will contain lessons to teach you some programming concepts eventually leading up to you making some simple effects :)
Part 2!
First steps.
The time has come to learn some boring (
but essential) programming before we go onto the more fun stuff.
I am going to take a
procedural approach to this, some people would say you should take an
object orientated approach, others still would reccomend that you learn
assembly language so you can understand how a program is processed.
I will be taking the
procedural approach because it is simple enough to learn.
You do not need to know the difference between these conventions at the moment because all we are going to be doing is learning how to count, how to do aritmetic, how to store numbers and text.
I'll keep this to a minumum and then we can go onto drawing some stuff on the screen.
Lets get ready to write our first program..First of all we need to open our editor so go into the FBEDIT directory and double click its icon to launch freebasic, we need to start a new program now so click on the "file" tab at the top.
Then "new code file" from the menu that drops down.
a window called "untitled.bas" will appear, this is the window where we will be doing our coding.
From now on, everything you need to type I will be surrounding in
code boxes, you can highlight the things in these boxes and copy-paste into your editor if you want to save typing them yourself.
The first thing you need to know are
white space and
commentsThere are two ways of doing comments in your freebasic listings.
You can see them in the box below;
rem This is a comment
' And so is this!
You need to know that the
freebasic compiler
ignores comments and white space, white space is just blank lines or areas of blank text, you can
use white space to lay out your code neatly so it is readable, you would
use comments in your code so that you can see what your code is doing.
You should
always comment your code, the
rem command and the
' character are treated exactly the same by freebasic, they
are ignored!So the first thing that you learned does nothing but is the most important thing that you will learn today.
put as many comments into your programs as possible so you can go back at any time and see exactly what is going on.
So let's put some comments in our program, it's a good idea to put what the program is going to do in the comments.
' Program 01 "Hello World"
' Written by me on 17th July 2009.
' --------------------------------
You will see that fbedit colours these comments in green when you type them in.
In fact it's pretty useful like that, it colours different parts of your program according to what they do to make it more easy for you to read it.
Here's the program you need to type then...
' Program 01 "Hello World"
' Written by me on 17th July 2009.
' --------------------------------
'Open an 800 pixel wide 600 pixel high screen
Screen 19,,1,,
'Print our message
Print "Hello World!"
'Wait 3 seconds (3000 milliseconds)
Sleep 3000
'Exit the program
End
There really is no time like the present so lets run it and see what happens..
First we need to save the file.
click "file" on the top of the screen.
Then "save as"
and call it:
helloworld.bas
You'll notice that the tab has changed its name to "helloworld.bas"
We need to do a couple of things to run the program.
The "make" tab at the top of the screen, click on that and select "compile".
When it has compiled you will notice a file called "helloworld.exe" has appeared in the directory with the helloworld.bas file.
This is your compiled program, you can either run it by
double clicking on it or straight from fbedit by pressing
shift and f5It opens a screen, (I am not going to go into details of this command as we will be using a different method for screens later on)
Prints Hello World on the screen
Waits 3 seconds
Then exits
It may not seem like a lot, but there are some concepts to learn here, the programs execution starts at the
top line.
The top line is white space which is ignored, so are the next lines (which are comments), the
first command that is looked at is the screen command.
It opens the screen
the
next command it comes to is the print command.
It prints out our message on the screen.
Then it comes to the
sleep command.
It pauses for 3000 milliseconds (3 seconds)
then it encounters the
end command
The program is safely terminated.
The concept that you need to grasp from the outset is that of the list, this is why programs are called listings,
each item in the list is executed one after the other. just like going through any list and reading off each item one by one.
This is as simple as it gets, clearly a program is just a list of instructions, the computer has an internal marker to keep track of where it is in the list, the list contains commands for the computer to carry out, it executes an instruction, moves the marker down the list to the next command and executes that, repeating the process until the list is finished.
We'll look at two of the commands here.
Firstly the
print command.
Only briefly because this is going to be used to output the results of some stuff we do in a little while.
At its simplest, the
print command is followed either by a variable or some alphanumeric text (letters, numbers and symbols).
Our "hello world" message is surrounded in
quotes "" You'll notice that fbedit coloured them red, the message within was coloured black and this is what got printed to the screen. There is another variation, we'll come to that in the next tutorial, but putting it simply, the message to be printed is contained within a pair of these quotation marks.
We will use the print command in the next few tutorials, but we'll be moving on to better things as print is very limited really.
The next one is the sleep command.
It was necessary to specify a delay before the program ended otherwise it would have been all over before you had a chance to see it.
You type the command;
sleepfollowed by a delay in milliseconds
1000 milliseconds
= 1 secondSo.
Here's one last example, apologies that this tutorial is very basic(pun intended), we will do some more interesting stuff next time!
Your excercise is..
Open a new source file
type this listing;
' Program 02 "Hello World 2"
' Written by me on 17th July 2009.
' --------------------------------
'Open an 800 pixel wide 600 pixel high screen
Screen 19,,1,,
Dim As Integer a
'Print our message
Print "Hello World!"
'Wait 1 second (1000 milliseconds)
Sleep 1000
'Print our message
Print "This is my second attempt!"
'Wait 2 seconds (2000 milliseconds)
Sleep 2000
'Exit the program
End
See if you can work out what it will do before you run it.
Now modify it to add some more messages at the end.
See you in the next one!