DarkBASIC Programming/Introduction to Programming

First of all, thanks for checking out this book on DarkBASIC. It's the first WikiBook on the subject of DarkBASIC Programming. Not everyone can program, but in the information age I believe that it's necessary for everyone to gain the skills to use different types of technology. Especially, computers and programming. Today and for the next 30 days you'll learn a lot about DarkBASIC Programming and a lot about what you can accomplish using a computer. DarkBASIC is all about making DirectX do your evil bidding and your domination of the world of computer game programming. I hope you read and contribute to this book, as well as rant because then I can fix stuff others will insult. I hope you enjoy!

In this tutorial I'm going to assume you have no prior programming experience, or else you wouldn't be reading this book. You would pick up the manual, compare it to C++, and program in DarkBASIC easily. First of all not to scare you but game programming is not easy and secondly you are not going to make a <insert copycat blockbuster game here> killer or clone or whatever in DarkBASIC for a long time. I'm also going to assume you have v1.0 of the "classic" or non-pro edition of DarkBASIC or else with another version you'll have some problems running this code unfortunately. Programming is not a new concept, and there are many hundreds of languages such as DarkBASIC out there, one such programming language comparable to DarkBASIC is BlitzBASIC, and you may have heard of Visual Basic.

So what is programming?Edit

This isn't a stupid question. Programming is not just making applications for Windows, or talking a language your computer understands. Programming is input, process, and output. If you take computer sciences, chances are you'll be doing program outlines, but right now you're a hobbyist programmer so let's keep it simple. Not all of us know VC++ or Pascal. DarkBASIC is game oriented. You can make applications in it, but it's harder. There are no message boxes in the version we'll be using. But DarkBASIC is easy and fun, especially for beginner's and junior programmers. Instead of having to write 1000+ lines of code to put a 2d character on screen you'll write one, instead of writing a massive program to make a cube spin you'll write a simple and human readable one in 20 or less lines. If you have no patience, take it slow and easy and don't move on until you understand it all or else you'll be bald by the time you finish this wikibook. I will say this: this book is a work in progress. I'll be finished as soon as possible so, bare with me please. Programming is simply entering lines of code that once compiled, or is run, tells the computer to follow out a task until it's done. What's involved is input, or you programming; processing or computing; and finally output, what you get to see.  

Figure 1.1(This is the Model of Input, Process and Output.) So you know: A coder is another word for a programmer.

All programs follow the above method, since every program is (1) certainly programmed, (2) is certainly compiled, and (3) certainly displays results. Now, just what is code then? Code is the recipe for your program. Computers won't do a task wrong. You'll do the task wrong. To keep your program from doing things that could harm computers, the compiler(or program that checks to see if the program works) runs the program and generates syntax errors (if there's something wrong). These syntax errors, tell you that you made a mistake and you must fix it before you can see your program(in most cases). So, computers don't make mistakes.

There are many sorts of errors also! The most common is called a syntax error . A syntax error are mistakes in your program's code. A programming language like a written language is incorrect if it contains things that are gibberish. Like in English, asdfjdj is not a word, it's gibberish. Just like in DarkBASIC, print is a command, where as printf is not. Another kind of error is called a run-time error, this is when your program compiles but you don't get the results you want. Such as if your writing is sloppy, the word "hello" may look like jello and the person will get the wrong information from it. Run-time errors are things that aren't suppose to happen, like when in your favorite video game, when a character can sometimes walk through a wall, or the program crashing when this happens.

The process of fixing your mistakes is called debugging. You'll get familiar with this; half your time or more will be spent doing debugging. So as much as possible, save, compile, debug, and run. It'll save you lots of anger, and stress. Finally remember this: with computers, the language goes through assembly or getting put into binary, and sent back to your programming language. If the binary pattern is correct, then you have no syntax errors. Remember, 0s are off or false, and 1s are on or true. Remember when I said assembly above?

Well, here's how it works. First off, you compile or check syntax, then the code you entered passes through what's called machine language or assembly (its name changes depending on what its doing when it's compiling its assembler). Then it becomes pure binary (which is not human readable but meant for computers; they cannot understand anything other than 0s and 1s). Then it is sent back to the compiler where if the binary matches what's correct, it gets executed. If it doesn't, you get a syntax error and must debug. Now, don't quote me on that but that's basically what happens. So now you're ready to begin programming in DarkBASIC and will know what I talk about.

One more thing: DarkBASIC is not case sensitive. If you don't know what this means, it means that DarkBASIC does not distinguish between upper-case letters and lower-case ones.