Warning: This is a tutorial on general programming. This will not go over specifics like "How do I move a sprite" or "How do I make an RPG". I'll go over the concepts of programming, which I think are more important than learning the specifics. It's like learning how to play an instrument or learning how to draw: you could learn how to play a specific song or how to draw a specific thing, but that won't help you when you want to learn a
different song or draw a
different drawing.
This WILL take a long time. If you're not up for learning a lot of things that aren't
directly related to making the game you've always dreamed of, you might get bored. We will be making toy programs (and possibly games), but the cool stuff won't come until later.
Next tutorial (part 2)
Introduction
What's going on here?
We're going to learn how to program, of course! Programming is how you control a computer. A computer is just a box that accepts commands. You write a list of commands (a program) and the computer follows them exactly. It's like having a super smart, super obedient butler: you can give him a list of things you need done, and he'll go do them exactly the way you tell him to. But just like butlers, computers accept many different languages. These different programming languages follow basically the same rules, so learning one language will open up the possibility of learning more languages pretty easily.
We're going to be learning how to program in SmileBASIC, which is a more advanced version of the ancient programming language BASIC. It's a relatively easy language to learn, and SmileBASIC has some nice language features which make it easier to make games. I'm going to be using the term "computer" when I talk about programming, even though you're likely using a 3DS. A 3DS is a computer too though, so it's not all that weird. There is little difference between your 3DS and your computer, so the concepts we'll go over can apply to both.
A bit more about computers
So everyone basically knows what a computer is at this point. There's so many computers that you'd be hard-pressed to find someone who DOESN'T know about them. What might be a little more mysterious is how they work. We're not going to go super far in depth here, but it's important to know what you're controlling before you start controlling it.
A computer is a logic machine which accepts inputs and produces outputs. That's all it is. These inputs could be the mouse, a touch screen, a sensor; anything that can be broken down into a digital signal. The outputs can be video, audio, motors, and ANYTHING else a computer can interact with. The computer in your television accepts input from the video cables and outputs an image. The computer in your wireless headphones accepts input from the wireless receiver and outputs an audio signal. The computer in your fridge accepts input from temperature sensors and outputs a signal to the compressor (the thing that makes the cold). All of these things need to be told HOW to translate inputs into outputs though, and that's what a program does. It's a set of instructions that tells the computer (through math and logic) how to interpret the input and what to output in response.
There's a liiiitle bit more to it though (sorry, I know I lied). Sure a computer can translate inputs into outputs, but if that's all it did, it'd be a pretty boring system. What if you want to look for a
sequence of inputs and produce special output? What if you wanted to do different things based on
when the input was received? For this, you have to have state (like a state of being, not the state of Florida). State means the computer will remember some amount of inputs and be able to produce different output than just the individual outputs for each of the individual inputs. Let's look at an example: imagine a vending machine where you have to type in that stupid 3 digit code just to get that delicious beef jerky. Let's say beef jerky is E35. If the computer inside the vending machine didn't have state, how would it know when you've pressed all 3? Without state, it would still be able to display each letter as you typed it because it's reacting to each press. But with state, the vending machine can
remember that you've pressed E, then 3, so that by the time you press 5, it'll be in the correct
state to vend you that jerky (and it better be teriyaki or you're not allowed to continue with this tutorial). For computers, state is achieved through memory. A computer is able to remember or "store" values for later use, which gives it the ability of state. This concept of state is one of the most important things in the programming and computer world, so make sure you understand it. State is just the computer's ability to remember things.
aside
As an aside for those who know, yes, there are programming languages which have no state (functional programming comes to mind). The only problem is that these programming languages are still built on a system which remembers state (a functional language can't exist without the stack), and you still need a computer (which is a ridiculously stateful machine) to run it. So yes, state is an extremely important concept.
Super Duper Basics of Programming
Command types
So a computer is a thing which accepts inputs, produces outputs, does math and logic, and remembers stuff. Cool, so it would logically follow that since a program controls a computer, it will also control input, output, math, logic, and memory, right? RIGHT! Yeah it's cool, there's no tricks here. Even the most complicated commands in a program still boil down to input, output, math, logic, or memory (or some combination of those). For instance, in SmileBASIC, your inputs are the buttons, keyboard, touchscreen, and microphone. There are commands for handling each of these. Your outputs are the screen, the speakers, and files. Once again, there are many commands for each of these. SmileBASIC can do basic arithmetic, perform conditional logic, and read or write values in memory. Using these, you can basically make anything.
Handling Memory
A computer only sees its memory as a big area to write whole numbers. But we don't work with just whole numbers, so programming languages like SmileBASIC build on top of this system to allow us to store decimals, sequences of characters (like what you're reading right now), and blocks of data. This is called a type system, because they've created different "types" of data on top of the memory system. Programming languages hide the simplicity of a computer and give us easier to use tools. Sure, we could manipulate the memory directly if SmileBASIC let us, but that would make it take longer to program even simple things. Imagine that instead of buying flour at the store to make a cake, you have to grind the wheat yourself. What a pain, especially if you had to do it EVERY time. We're going to work with all of these types eventually, and we'll go over the details of each when we get to it.
Programs and the Computer
A computer is made to run programs, and that's it. Windows is just a big program. This website is just a program. SmileBASIC is a program, and it's run by the 3DS's operating system (which is also a program). Basically if it's running on a computer, it's a program. I mean there are certainly special types of programs, and not all are equal. But at the core, all programs are made to control the computer in some way. When a computer first starts, there are no programs running, so it has to look in a special place to find the "first" program. In computers, this is usually some kind of loading program stored on the motherboard to load your BIOS. Then the BIOS program looks at another special place (usually the hard drive) to run the OS (operating system) loader program, then the OS loader program runs the main OS program which then spawns like thousands of other programs which eventually make up your operating system. You don't have to remember all that (it's not really important), it's just important to realize that there's nothing special about this. There's no magic, it's just programs upon programs upon programs.
It's important to note that a program doesn't DO anything until it's run. When you write a program, it's just like writing an essay on your computer. The essay doesn't DO anything, and neither does the program, because they're just sitting there. You have to
tell the computer to run your program. We'll go over how to do this on SmileBASIC later, just remember that a program is just a file UNTIL you tell the computer to run it. When the computer follows the commands, then your program has meaning.
Conclusion
Don't feel overwhelmed if it feels like a lot of information. Programming isn't about memorizing all this stupid stuff, it's understanding the ideas and tools and putting them all together. It's like working with Legos: you don't need to memorize how each and every Lego is made and all their part numbers, you just have to know how Legos work in general and you'll be able to put them together into something cool.
So a computer is a machine which works with input, output, memory, logic, and math. A program controls a computer. Computer land is all about combining smaller things into bigger things (like making programs that run bigger programs). Oh, and you're gonna need to think
logically in order to program (I forgot to mention that).
Next tutorial (part 2)