Blitz3d Tutorial

0 views
Skip to first unread message

Hebe Newnam

unread,
Aug 4, 2024, 8:49:47 PM8/4/24
to tumbknapegfred
Brandnew to working with computers, starting with something easy. Going through the Blitz3D Blitz BASIC tutorials. Been experimenting a bit with arrays but I keep getting the error: Expecting end of file error.I'm not sure what's causing it. I also occasionally get "End of line error"Here is the code:

I figured it out. It was a spelling mistake. I added a(n) ) on accident. that caused it to not register the code.It's not just that but the identifier "MathTest" cannot be used like this. Meaning I must have screwed up the array somewhere.




If you are interested in learning how to create your own computer games,

you have come to the right place! This is the best site around

for new users of the programming language Blitz Basic.





Blitz Basic comes in many flavors, you can check out BlitzBasic.com for more info!



Blitz makes programming so easy that anyone can now produce games of great complexity.

No matter what kind of game you are looking to create, BlitzTutorials.com has the info

you need and much more. From platformers, to space shooters and puzzle games, it's all here!

Browse around and enjoy our growing collection of both free and premium tutorials.






This guide was written for people new to BlitzMax and perhaps even programming, especially recommended to those who want totake a first step in Object Oriented Programming (OOP) in BlitzMax. This Introduction should work if you are converting to BlitzMax from any otherprogramming language, including Blitz3D/Plus. It's not written as a BlitzBasic & BlitzMax tutorial. My aim is to giveanyone the opportunity to get a good start in learning the fantastic BlitzMax. If you are converting from Blitz3D/Plusyou will get a shock, because there is a lot of new stuff. Ways have changed but I promise you, it's for the better.When you have taken the first steps and learned your way around there is no other place like BlitzMax ;)


Also the code in this tutorial may be hard to paste, sometimes it laps pages and the tabs don't seem to copy all thetime. A good way to learn is to do. Read my examples but try to write them yourself. It gives good coding practice. Ifyou want to use any code within this guide for anything, please do so, the code is public.


You probably know this: A variable is a place where you may store a number or a text. There are different variable"types" depending on their use. Here are the most basic types: Integers which store numbers, Strings which store textand Floats which store decimal numbers. We also have object-"types" which includes these basic types such as Arrays,Lists and your own custom Types (more on these later). See the Language Reference if you want more information aboutBlitzMax variables.


If you want to increase a variable, let say speed. You can write speed = speed + acceleration Or in a shorter wayspeed :+ acceleration. Both are identical, but the last is shorter. It is required that you declare your variablesbefore use.


If you want to force all variables to be declared by you, use the command Strict which gives you a compile error ifthere is a variable that you didn't declare like this: Local/Global VarName:VarType , 2ndVarName:VarType


I do not use SuperStrict in my examples, so if you want to use SuperStrict make sure you declare all the variables. You shouldalways use Strict unless you are very lazy or are making a tiny examples or minor tests, it will help you findmisspelling-bugs before they occur and save you hours of debugging.


A variable can be Global or Local. Globals can be accessed from the entire program. Locals on the other hand are morecomplicated, cause where they exists depends on where they where declared. To declare a local variable use the keywordLocal in front of the variable name. If you declare a local variable in a function it will only exist in that function.If it is declared in a loop if will only exists as long as you are in that loop. If a local is in an if-statement itwill only exists in that if statement.


You can also declare constants. A constant will have the value you gave it when you first declared it. The value of aConstant can never change, it will always stay the same. If you try to change a constant'a value the complier will warnyou when you compile - build. Constant is useful for values that always will stay the same. You'll encounter constantsin examples later on.


Comment much, it helps others who read your code and it will help you, because eventually you will forget why you did ita certain way or why you added that function and what it did. While you are new to programming I would advice you tocomment almost every line. To explain something is a good way to learn it, use comments as your walking stick when youtake your first steps in programming and BlitzMax.


If statements are used if you want to check if a condition has been meet and then act upon that. This example doesnothing special, it just shows you how to use If, Else If, Else and EndIf. (A,B,C and R are variables)


When to use Then? You can put it after your If expression. The use of Then, is not required and I think the code isjust as easy to read without Then. Like this, If A = 1 Then B = 2 is equal to If A = 1 B = 2. If you take aBlitzMax file and delete all Then, it will run the same. Use Then if you think it helps you read the code. When Iuse then, then it is to make an ifstatement on one line more readable, like in the example above and in the examplebelow. My advice is, never use then if your if-statement is not on one line.


True and False can be used in If-statements, usually to make the code a little easier to read, you can livewithout them*. False means something is equal to 0, True if it's not equal 0. Many functions return 1 if success andelse 0.


DrawRect, DrawOval, DrawLine, DrawText and Plot are some of the built in graphics commands. They simplydraw a filled Rect/Oval, line, text and pixel respectively. If you want to know how to use these commands check outthe Module Reference. To be able to use your graphics card you will first need to set a graphics mode - specifyingthe resolution you want to use. Just enter Graphics 800,600 for a full screen resolution of 800x600.Graphics 800,600,0 gives you windowed mode, very good for debugging. Note: Keep reading there is a sample below!


A loop is a way to tell Blitz to do one thing several times, or in games to update the game until the game is ended.Loops are what makes games run in real-time. This loop below starts at Repeat and when the program reachesUntil X >= 800 it will jump back to Repeat unless the condition is met. So it will loop depending on X. Try torun the example on the next page:


In BlitzMax everything you draw is drawn to an invisible Board. You can draw how much you want to this board butit won't show up on screen. You can see it as if BlitzMax is drawing on the back of your screen, the when you wantto show it, you Flip the Board and we can see what have been drawn to it. If we keep drawing a lot of stuff andFlip, then continue draw a lot of stuff, the board will be a mess. This is why we clear the board after we haveflipped it, but this also means we have to redraw everything we previously had at this board! And that's how itworks. This board is known as the back buffer. You do not need to (and cannot) set the back buffer as inBlitz3D/BlitzPlus. This method with flip and clear is called double buffering and is done to prevent flickering graphics.


This part is identical to BlitzBasic. At the Top Left of the screen we have the point 0,0. Add these lines to theabove example, just one row below "Repeat": (They might be hard to see, try fullscreen by removing the last ",0"in graphics )


The X-Axis is the Horizontal Axis from the left side of the screen to the right side, The Y-Axis is Vertical andtravels from the Top to the bottom. The resolution is what determines how many pixels you will have at each axis.So in our example the screen width (in pixels) would be 800 and the screen height 600. The more pixels at screenthe more calculations is required by the computer both in 2D and 3D. You can get the current screen width withGraphicsWidth() The Line X1,Y1,X2,Y2 command creates a line from X1,Y1 to X2,Y2. Add the following to our example:DrawLine 40,40,80,80 ;DrawLine 40,40,40,200


To optimize the above code add a new variable called speed after Graphics but before the loop. Now replace all 1'swith this new variable speed. Go to the place where you have your variable speed (at the top) and set it = 5.If you done it right. You'll notice a speed increase when you drive around. Also note that all keys have nameswhich start with Key_ The a-key is Key_A and so on for all letters and numbers. See the scan code section of themanual for a complete listing of keycodes.


The name, id and age are the function Collectdata's input parameters. The function returns a String. A function canreturn any type of data including objects. What type it returns is specified after the function name , the "$" forString. If you change this to an int "%" or :Int. Function CollectData:Int(.. Now you will receive a commonerror: "Unable to convert from 'String' to 'Int' ". The function does actually return a string but you specified youwanted it to return an Int and BlitzMax warn you something is wrong. But this does not mean you can't convert stringsto ints, see below.


Note that in the function that C=0, which means use C=0 as default if none specified. If the function would have hada C% only, without the =0 part, you would encounter a compiler error doing Add(2,2) but it would work fineto Add(9,9,9). Note that it is important to comment you functions. Write what the parameters are and what it returnsand what it does. Always try to keep your functions less than a page in size. If they become larger try to dividethem up into several functions. Functions can be used inside other functions. In the long run good comments andfrequent use of functions will save a lot of your time! If you don't specify any return parameter as in this latestexample, BlitzMax, in Strict mode, assumes you want to return an int. Nothing = Default = Int.

3a8082e126
Reply all
Reply to author
Forward
0 new messages