I figured I would write an in-depth tutorial on the basic to advanced topics of BlitzMax!
Here you all go!
(Please tell me if I missed anything, or you need help with something.)
---
Part 1: What is BlitzMax?
---
Some of you may be wondering, What is BlitzMax?
I will try to answer that question in this part.
BlitzMax is a Compiled (creates an EXE) programming language created by Mark Sibly (from Blitz Research, Ltd. http://www.blitzbasic.co.nz).
BlitzMax is different to Blitz3D/Plus in many, many ways; but I will go over these topics as if the audience has no idea what those two are,
or has never heard of BlitzMax before.
BlitzMax is an Object-Oriented Basic Dialect.
You can do a lot of really cool stuff with it, that you may not be able to do with, say,
Commodore BASIC. Pretty much, you can do with BlitzMax what you can do with (almost) any other programming language
out there. I have seen compilers made in it, I have seen games made in it (which is what it was designed for), I have seen pretty much everything but an operating
system made in BlitzMax.
---
Part 2: What is the difference between a compiled and an interpreted language?
---
The easiest way to put it is in an interpreted language, code can not be natively made into an executable, but in a compiled language, it can.
Interpreted code is ran through the interpreter, ie. php.exe, python.exe, etc. and that interpreter runs the code right then.
Compiled code, on the other hand, is ran through an interpreter, ie. bmk.exe, gcc.exe, fbc.exe, etc. The compiler creates assembly language code that is
then ran through an assembler (fasm, masm, nasm) and a linker (ld) to create an executable (.exe).
So, as you can see, compiled languages have a lot going on in the background; it is worth it, though! Compiled programs run faster than code being put through an
interpreter. It also allows you to distribute your executable without giving away source code.
There is still ways to compile interpreted languages, but they are normally not officially supported. I think there was/is a PHP2EXE converter somewhere around,
but that name is probably incorrect.
---
Part 3: Obtaining Prerequisites for this tutorial
---
You will need some stuff to get you through this tutorial. Here is what you will need:
*BlitzMax http://www.blitzmax.com/Products/_index_.php
*minib3d http://www.blitzmax.com/Community/posts.php?topic=96521
*MinGW http://experimental.thegamerboard.com/Files/MinGW.rar
The rest I will walk you through how to make. This includes the programs, as well as the framework you can use throughout this tutorial.
---
Part 4a: Getting Started; installing BlitzMax
---
BlitzMax can be obtained by, after buying it from BlitzMax.com, logging in to the website and clicking on Account->Product Updates->BlitzMax (the latest version).
If you don't know how to install a program, this tutorial is going to be too hard for you right now, so you should go learn more about the computer and come back
after learning how to install programs, and, if you haven't already, make powerpoints and word documents.
TIP (Windows 7 & Vista users): Right click on the BlitzMax icon once it is installed, and go to properties. Then, go to compatibility, and enable "Run this program as
administrator". This will probably save you some hassle later on.
---
Part 4b: Getting Started; Installing minib3d
---
once BlitzMax is installed, make sure you are logged in to an administrator account. Next, extract the archive downloaded from BlitzMax.com or google code, which
contains the minib3d code. Then, copy the folder labeled sidesign.mod to C:\BlitzMax\mod or wherever you installed BlitzMax to.
---
Part 4c: Getting Started; Installing MinGW (Windows Vista/7 ONLY, If you are using XP, please tell me how to do this on that OS, so I can update the tutorial.)
---
1. Extract the archive MinGW to C:\
2. Go to Start then type in "System Environment Variables"
3. Click on the "Edit System Environment Variables" link in the options that pop up, then click on the "Environment Variables" button.
4. Find in the Second Listbox the variable PATH (upper or lowercase, I forget) and click Edit. In the box that pops up, append (add to the end) of the textbox
with all the paths in it ";C:\MinGW\bin" without the quotation marks. The semicolon is needed, otherwise it won't work.
5. Click OK, and add a user environment variable to the top listbox named "GCC_EXEC_PREFIX" and the value is "C:\MinGW".
6. Add another environment variable to the same list, named "MinGW" and the value is "C:\MinGW" too.
---
Part 4d: Getting Started; Building Modules
---
Open BlitzMax, and press CTRL+D (Control and D) to build the modules.
Go to the Program menu, and click on "Rebuild All Documentation" to rebuild the docs for the minib3d, and everything else.
---
Part 5: Int Main (Or Not!)
---
This part is a quick rundown of the BlitzMax syntax for users of C/C++/PHP who have no experience in BlitzMax. It is designed to make the transition easy.
There are no semicolons in BlitzMax! Well, there are, but they are just used for putting multiple commands on the same line.
Code: Select all
Write "Hello";Write " World"
Use the following chart to make the transition:
Code: Select all
!= <>
== =
! Not
Code: Select all
+= :+
-= :-
/= :/
*= :*
<< Shl
>> Shr
Code: Select all
<
>
<=
>=
&
|
*
-
+
/
=
Functions can NOT be overloaded. This also applies to type methods, and static type methods.
The only way to make overloading work is to use inheritance in the types.
There are no Curly Brackets in BlitzMax! Well, there are, but they are never actually used in most applications, and this tutorial will (probably) not
outline how to use them. They are used for metadata, and I have only read about it once in a forum post on the Blitz Website.
The replacement is the use of the End X Command.
Code: Select all
If X = 1 Then
Do Something
End If
---
Part 6: Data Types
---
I would explain this, but it is better off if you start reading some of the parts of the documentation that are actually usefully documented.
Open the Official BlitzMax IDE, and go to Language->Data Types. There is an attempt to document the data types there. It is very important that you read through the data
types to understand why I use certain ones where in the code. This is mainly for the Integer Data Types (Byte, Short, Int, Long).
---
Part 7a: Hello World!
---
Here comes the fun part! You will write your first program in this section!
First off, let's start with the standard Hello World program:
Code: Select all
Print "Hello World!"
Now, this is great, but what if we want our users to be able to run this. They need the BlitzMax IDE, right? Wrong!
Go to your folder that you saved the code in, and you will see the exe named after the code file. Run it!
Uh Oh, it opens and quickly disappears! This is our first bug! (Well, maybe not a bug, but an undesired effect.)
Add this in to the bottom of the code:
Code: Select all
'Delay for 5000 Milliseconds, or 5 Seconds
Delay 5000
Go run that EXE again, and see what comes up!
Modify the program a bit. Change the 5000 to something else, and maybe make Hello World! something else too.
Go get a beer, or in my case, a soda, and relax. You just made your first program!
---
Part 7b. Code Analysis
---
You may be wondering why something didn't just come out of your printer.
Print basically means show on the screen. So, Print has nothing to do with the printer, and I agree, it is named wrong.
It's name has to do with BlitzMax's roots in BASIC.
---
Part 8a: Variables & Input
---
Okay, so this works fine, but what's a program without user interaction, or input?
To be honest, it isn't a good one!
Let's make our program ask for the user's name, store it in a variable, and say hello to our user.
Here's the code!
Code: Select all
'print our cool message first!
Print "Welcome to my Second Program!"
'then, ask the user for their name, storing it in a variable named "name"
Local name:String = Input("What is your name? ")
'finally, say hello to the user!
Print "Hello, " + name + "!"
'wait so the window doesn't close
Delay 5000
Part 8b: Code Analysis
---
Print is the same kind of thing in the first line, but in the second Print statement, we used the + operator to add stings together.
A string is pretty much anything that can be shown on the screen. Well, it is actually more than that, but all you need to know is that it is only stuff that
can be shown on the screen, or typed from the keyboard.
Input first displayed a message, then it Waited for the user to type in something and press enter.
It stored the user's input in a string variable named "name". We then proceeded to print the user's name, and Delay for 5000 milliseconds, or 5 seconds
to stop the window from closing immediately.
---
To Come: Part 9a: Guessing Game
---