Seth Hopkinson's QBasic Page
PLEASE NOTE: This is our OLD web page (circa 1996). It is no longer maintained. Some of the information contained
on this page may be outdated and/or no longer true. Anything that is "under construction" here, will never be finished.
Any broken links will not be repaired.
To view our current web page, Click Here.
Seth Hopkinson's QBasic Page
* QBasic Programmer's Forum *
"Sharing my programming knowledge for the advanced,
providing a foundation for the beginner."
The most commonly asked questions:
Where can I get Qbasic? -- It comes standard with
MS DOS 5.0 and above. You can also get it on your Windows CD (Win95 and above).
This article tells you how to access it.
QB App Path -- How can I tell what folder (directory) my QBasic Program is running in?
QB VGA Palettes -- How to set colors in SCREEN 13 (VGA 320x200, 256 colors)
General Information -- Some general information all
QBasic programmers should read, especially beginners.
QBasic Compiler -- Is there a way make my QBasic
programs into .EXE files? How can I make QBasic run my programs faster?
Arrays -- How do I make maps, like you did in Shalimar
and Dungeon? How do I make lists of items (like weapons, armor, ect) like
you do in your games?
Files -- How do I use data files in my programs? How
can I save variables, maps, and arrays to disk?
Tiles -- How did you do the tiles, like in Sceptre of
Shalimar and Space Duel? After you have a good understanding of FILES and
ARRAYS and GRAPHICS, you are ready for the good stuff. For GRAPHICS help,
look up the SCREEN, PSET, LINE, and CIRCLE statements in online help...
I am currently writing a book on programming. If you like what you
see here, you would definitely be interested in gettin a copy of my book.
I AM NOT FINISHED WRITING THE BOOK YET, in fact I haven't even given it a
title yet! I don't know when (or IF) I will finish it, or who will publish
it. If you like, you can
click here to send me an EMail.
(don't change the provided Subject or your message will get whacked by my anti-SPAM filter).
You can EMail me questions or comments at:
seth@alphaomegasystems.org.
(again, don't change the provided Subject or your message will get whacked by my anti-SPAM filter).
Due to the tremendous volume of EMail I recieve, it may take awhile for
me to send you an answer if you EMail me. Comments are appreciated.
Questions can sometimes 'get on my nerves', but I may answer them if
I am in the mood. Generally, I won't answer a question if the info
can be easily obtained in the QBasic Online Help (ie: "What does the SCREEN command do?").
I also probably won't answer extremely vague and general questions
("How could I make a game like Sceptre of Shalimar?" is a good example. Way too vague.
The answer would easily fill a book or two!!!).
* Where can I get QBasic? *
-- NO, you can not download QBasic or Quick Basic from my Web page...
Unless Microsoft gives me permission! I already had some damn lawyer Email
me threatening to bring up a case with Microsoft if I did not remove the
files -- they were ONCE on my web page available for anyone to download...
You all can thank that power-hungry S.O.B. Lawyer for ruining it for everybody!!
I've EMailed MicroSoft and asked their permission,
and got no answer for the longest time. When I finally did get an answer,
it was not all that helpfull and did not really answer the question I had
asked them (they gave me a line about how QBasic was no longer a product they
offered, so it wasn't available to resellers... As if I were running a Software
Store or something). Anyway, for now the files are unavailable on my WEB page.
-- QBasic comes standard with MS DOS 5.0 and above. So, if you have an older
computer that runs MS DOS as its primary OS, you will find QBASIC in the
C:\DOS directory. Just type in QBASIC at any DOS prompt to run it.
-- Windows users (Win95 and above) can copy the two QBASIC files from their Windows CD.
They are usually located in the \OTHER\OLDMSDOS folder,
however this will probably change as newer versions of Windows come out.
If you can't find QBasic in this folder, try a FIND or SEARCH for it... Go
into My Computer, Right Click on your CD Rom Drive, and choose "FIND" or "SEARCH".
Look for filename QBASIC. You might also try looking up QBasic in the online
help (Start Menu -> HELP) or in the README.TXT file on the Windows CD.
Anyway, once you've found the QBasic files, make a folder called QBASIC and copy
the two files into it (they are called QBASIC.EXE and QBASIC.HLP but you might
not see the .EXE and .HLP if you have "Show File Extensions" turned off). When
you want to run QBasic, just double-click on the QBasic icon in the QBasic folder.
* QB App Path *
HOW CAN I TELL WHAT FOLDER MY QBASIC PROGRAM IS RUNNING IN?
I get asked this all the time.
I also get asked, "why would I want to do that?".
The following is an answer to both questions:
The basic concept is very simple:
Have QB program run the DOS CD command.
Store the output of CD in a file.
Open the file in QB program.
Store the contents of the file in the PATH$ variable.
The specifics:
SHELL "CD >temp.txt"
OPEN "temp.txt" FOR INPUT AS #1
INPUT #1, path$
CLOSE #1
SHELL "ERASE temp.txt"
The QB SHELL program runs the specified command on an off-screen DOS Prompt.
The CD command, when ran by itself, will display the folder you are currently in.
The > operator re-direct's a DOS Command's output to a file (in this case, temp.txt)
The ERASE command is similar to DEL (DELETE), except it doesn't bring up a Y/N prompt.
OPEN, CLOSE, and INPUT# part stores the contents of the temp.txt file in a variable
(in this case, PATH$).
How is this useful, you ask?
Well, lets say you are trying to load Graphics (or any other Data file). How do you
know which folder to load them from? It might be "C\Programs" on your computer, but
"C\Games" on someone else's computer, and maybe even "C\Program Files\Downloads" on
someone else's computer...!
So how can you deal with this?
The answer is to use the QB App Path thing I describe above. If you always load your
Graphics, Data, ect from PATH$ then it won't matter which folder the user runs your
program from... It will always work!
* QB VGA Palettes *
First make sure you have the computer set to the correct graphics mode. Do this by
having a line that says SCREEN 13 at the beginning of your program.
Now, to set the colors, the commmand syntax is as follows:
PALETTE color, red + (green * 256) + (blue * 65536)
Where RED, GREEN, and BLUE are each a number from 0 to 63.
COLOR is a number from 0 to 255.
You must be sure all your numbers fall within these range(s) or else QB will give you
an error message. Be especially careful with that Red/Green/Blue equation!!!
Any standard graphics commands (LINE, PSET, CIRCLE, ect) will be able to use any of the
256 color numbers (0-255) that you've created. Remember that Color 0 is typically the
background color.
You don't need to enter in all 256 colors, there are defaults. However, I've found that
the defaults are not the same on all hardware (ie: different graphics card = different
default palette). So it is best to define any color you plan to use.
Special Thanks to Brian Bartels for his online article on VGA Palettes in QBasic
( http://alternatelogic.hypermart.net/files/palette.txt).
* General Information *
1. First off let me say USE THE ONLINE HELP!!! QBasic has a fantastic
reference manual built right in that most people don't know about. Just hit
SHIFT-F1 or move the mouse over to the HELP menu. Then go into the INDEX.
There ya go! A list of all the QBasic commands, complete with examples on
how to use them.
-- It really bugs me... People ask me stuff all the time and the answer is
(and has been) right there in the online help all along. So please, check
the online help first!
2. Next, let me say the best way to learn how to program is to look at other
people's programs. Just hit CTRL-C or CTRL-BREAK while a program is running.
This will stop the program and bring it up on the screen for you to look at.
Go throuh it line by line in your mind. Thats the way I learned most of my
stuff.
-- All the QBasic programs on the
Alpha Omega Systems MS DOS Download Page
are excellent candidates. Sceptre of Shalimar is a storehouse of programming
tricks. Dungeon and Space Duel are a little shorter and will be easier for
beginners to trace through.
3. If you are a beginner and are serious about programming, you really need
to buy yourself a book on QBasic. In America, such a book would usually go
for about $25. But a good programming book is money well spent! After you
buy the book, READ IT. Even if you only do 5 or 6 pages a day. And make
sure to type in and experiment with any of the programs listed in the book
right after you read about them, while it is all still fresh in your mind.
I am working on a QBasic book right now, if you are interested in it, Email
me and ask about it (see table of contents above).
4. Most importantly of all, START SMALL! I cannot emphasize this enough.
I've taught many people how to program, and so many of them want to just
rush out and program DOOM, or something equally complex, after only a few
weeks of study. YOU CAN NOT DO THIS. You will fall
fast and hard! You need to make simple little games and programs
first. Then try bigger and better things. And eventually, after you get
really good at it, THEN try to program your super end-all-be-all project.
Do you have any idea how long I was into programming before I made Sceptre of
Shalimar? I had made DOZENS of simple, smaller programs first. You need to
do the same. In the future I will upload some more of my simpler stuff as
examples, but for now you'll have to make do with Sceptre of Shalimar, Dungeon,
and Space Duel.
5. Finally, STAY WITH IT. Learning to program is like any other art or skill.
You'll get nowhere unless you keep at it day in and day out. Those who
give up early get no rewards. Those who continue to practice and persevere
reap large treasures.
* QBasic Compiler *
How do you make your QBasic programs into .EXE files? You compile them. How
do you make your QBasic programs run faster? Compile them.
-- There are two QBasic compilers I know of.
-- One is Quick Basic 4.5 which was published by
Microsoft a few years ago. Look for it on the WEB, someone is bound to have
it up for downloading on their WEB page somewhere. Usually goes by the name
QB45.ZIP. If you are lucky, you might even still find it in stores or in
Mail-Order catalogs. You won't find it on my WEB page for the same reason
you won't find QBasic (see above).
-- Anyway, Quick Basic 4.5 looks and feels just like QBasic. The only
difference is under the "RUN" menu there is an extra command -- "MAKE EXE".
This will compile your program into an .EXE file, and as an added bonus, will
speed it up by about 300%... Oh, some other side effects are that you will
no longer need QBasic to run it (it will run straight from the DOS prompt or
from a Windows icon) and other people will no longer be able to BREAK into and
look at your program. Make sure you SAVE your program before you compile it
or you won't be able to BREAK into it either!
-- The other is POWER BASIC which is a great ShareWare
product. PowerBasic will turn your code into an .EXE file, making it
faster, un-breakable, and stand-alone just like Quick Basic. But Power Basic
doesn't stop there. It allows your programs to be much larger than Quick
Basic or QBasic will, and has a host of incredible new statements and features
(mouse support, graphics, ect). They also offer a product called FIRST BASIC,
which is like Power Basic but does not have some of the new features.
FIRST BASIC is inexpensive (under $40) and will compile
any of your QBASIC programs. If you are interested, then by all means go
check out The PowerBasic Home Page.
* Information on Arrays *
Arrays are one of the most important programming concepts for people to master.
Once you learn how to properly use arrays, a whole world of possibilities opens
up to you.
In its simplest form, an array is just a numbered set of variables. Here's
an example of how to do things both with and without arrays:
Lets say you wanted to keep track of the ages of 10 people. Without using
an array, you would simply make 10 variables... Age1, Age2, Age3, Age4...
and on down the line. Then you design your program around this. When you
ask for ages, you would probably put up either a CASE statement or a whole
slew IF statemets that each point to an INPUT which asks for age. Something
like this:
INPUT "Enter Age of Which Person";x
IF x=1 THEN INPUT "Enter Age of Person #1: ",Age1
IF x=2 THEN INPUT "Enter Age of Person #2: ",Age2
IF x=3 THEN INPUT "Enter Age of Person #3: ",Age3
. . .
PRINT "Person 1's Age is",Age1
PRINT "Person 2's Age is",Age2
PRINT "Person 3's Age is",Age3
. . .
As you can see, this would quickly get monotonous. And if that weren't enough,
theres another problem... What if you wanted to do 11 ages now? Or 20?
Or 30..? And what if you wanted to keep track of both names and ages? In
any of these cases, we're talking about a major re-write of most of the
program. And a whole lot more monotony... There has to be a better way.
There is. USE AN ARRAY...
Whenever you use arrays, you have to first create them. You have to tell
QBASIC that you want an array, and also how big it will be. The DIM
statement is used for this purpose, and must always come at the beginning
of your program, before you use any arrays. It works like this:
DIM name(elements)
Where NAME is the name of the array (an array is named just like any other
variable) and ELEMENTS is how many "numbered variables" you want this array
to contain.
In the above example, for the ages of 10 people, we want an array called
AGE that contains 10 variables in it. So we would type in DIM AGE(10) at
the top of out program.
Once you have created an Array (with the DIM statement), you can use it
like any other variable, but with one small exception. Since an array
contains a number of variables in it, you always have to tell it WHICH one
of these variables you want to play with. This is done simply by following
the array name with a number in parenthesis. Like this:
Age(5)=10
Age(2)=7
What these two lines would do is set the 5th variable in the array to 10, and
the 2nd one to 7. You get values from the array in the same manner:
PRINT Age(5)
PRINT Age(2)
These two lines would print the value of the 5th variable in the array, and
the value of the 2nd one.
We call these "variables in an array" ELEMENTS. So to be proper, I would say
that Age(5) is "Age's 5th ELEMENT"... And Age(2)=10 would be worded as
"Set Age's 2nd element to 10".
The Coolest thing about arrays is that you can use a VARIABLE to specify the
element. So I could say Age(x)=10 to set Element X to 10... This is where
the real power and usefullness comes in.
Now here is that above "AGE" example written using arrays:
DIM Age(10)
. . .
INPUT "Enter Age of Which Person";x
PRINT "Enter Age of Person #",x;
INPUT Age(x)
. . .
FOR T=1 TO 10
PRINT "Age of person #";T;" is ";Age(T)
. . .
Notice how much simpler this is? And if we wanted to make it for 20 or
30 people instead, all we would do is change the number in the DIM statement.
No need to put in 10,000 more IFs... Arrays are a much better way to program.
How does this apply to games? Let me ask you something. Tell me how you
would keep track of the hit points of 5 characters in a Role Playing Game?
Or the stats of 7 monsters roaming around the screen in a scrolling shooter?
Or the locations of the last 25 bullets your player has fired?
Its all done by arrays... So learn this stuff well.
Incidently, here's how I would do arrays for the monsters.
Mx(N) -- Monster N's X position.
My(N) -- Monster N's Y position.
Mh(N) -- Monster'N's Hit Points.
Mt(N) -- Monster N's Type Number (number determines graphic, characterisitics, point value, ect).
You should be able to figure the other two out after looking at this.
Coming soon, 2-dimensional arrays
* How to use Data Files *
Coming Soon, Data Files (for now, look at OPEN, CLOSE, PRINT#, and INPUT# in online help)
* How to do Tiles *
-- The secret of the universe is the GET and PUT graphics commands.
Look them up in the online help. Basically what you do is store your tiles
in INTEGER arrays. Integer means that the Variable has a % on the end of it,
ie: Tile%(1)... You use GET to put a portion of the screen into an array,
and PUT to put a tile stored in an array back onto the screen.
-- So, let's say you have drawn a 20x20 happy face on the screen at
coordinates 10,10 and a 20x20 sad face on the screen at coordinates 50,10.
You program could be something like this:
DIM Happy%(1000)
DIM Sad%(1000)
SCREEN 13
''''
'''' LINE and DRAW commands to make faces (tiles) go here.
''''
''''
'''' Get tiles, store them in arrays
''''
GET (10,10)-(30,30),Happy%
GET (50,10)-(70,30),Sad%
''''
'''' Put tiles up in different places around the screen
''''
PUT (100,100),Happy%,PSET
PUT (50,50),Sad%,PSET
PUT (1,1),Happy%,PSET
PUT (299,179),Sad%,PSET
-- The PSET just tells PUT to copy the tile straight to the screen.
There are other options besides PSET (see QBasic online help).
-- Size of Arrays: To be on the safe side, just figure one element per pixel.
So if your tile is 16x16, a total of 64 pixels, DIM your array to 64 (ie:
DIM Tile%(64) in your program). There a bit more to array sizes than this,
but this is simple and will work every time, in any graphics mode (it is
foolproof).
-- This is more than enough to get you started, you'll have to
experiment around to learn more. Feel free to look at how I did it in
Sceptre of Shalimar. The gold mine is in the TileAt
SUB, in the FOR loops of the DrawMap SUB, and in the
LoadTile SUB. You will also want to look at the
Sceptre of Shalimar Tile Editor.
You are the
visitor since 29 Aug 2004.
Return to Alpha Omega System's Home Page.
This Web Page was created 4 Nov 1996 by Seth Hopkinson.
Last Modified 04 Apr 2003.
This WebSite is constantly under construction, we are always expanding/updating.