But how do you control this byte-shifting madness? Programming in pure machine language is nearly impossible. It was doable back in the BASIC days, but now, programs have become too complex. For this, we'll use a programming language. Programming languages lie closer to real languages like English, are not as complex and code written in it is more logical and easier to understand.
The problem is, a computer doesn't understand your 'modern' programming language. All instructions to the computer have to be presented in machine code. For this, you use a compiler. A compiler translates your modern code to machine language, allowing you to write programs using a modern programming language. (As an added bonus, your end user won't be able to see or edit your source code if you don't want to.)
And, oh boy, there are a LOT of programming languages. Some are exclusive to certain game engines, while others can be compiled to nearly any platform, and some are able to run in browsers.
What is code, actually? Let's look at this snippet of JavaScript:
alert("Hello World!");
What happens here? As you can probably tell, 'alert' is to alarm the user of something important. alert() is a function here. Functions do something, whether it is to check the distance between two objects, switch between equipment, making things blow up nicely, and so on. The most important functions are already included in your programming language, and you can write your own should to fit your needs.
Inside the brackets, there's some text: "Hello World!". This text is displayed inside the alert. The code language knows that it is a text, because we wrapped it inside quotation marks. (In programming, texts like these are called 'Strings'.)
Also, since you wrapped it up in brackets in front of alert, "Hello World!" is now an argument of our alert() function. That means that alert() will use this argument to do exactly what you want. alert() accepts one argument, and that is the text to display.
Arguments can be required or optional, and in this case, the argument is required (what is the use of an alert if the user doesn't knows what caused the alert?) Finally, there is a requirement about what kind of information the argument should be. Obviously, alert() wants to display a message, so the argument should be a string. We finish the current action by placing a ; although a newline will often also do the trick.
Shall we take the above a level further? Watch this code snippet:
if (confirm("Do you want a cookie?") == true)
{alert("Yeah right, you wish.")}
else
{alert("Okay then... Whatever.")}
Line number one contains an if-statement. If the question asked inside the brackets is true, then the code will enter the directly following {}-brackets, where the user discovers that we'd rather keep our cookies for our self. If not, then we just skip the code in the {}-brackets altogether.
Let's look closer at the question. confirm() is a warning, just like alert() we discussed earlier, but now, the user is presented with an yes or no choice. With alert(), the user always clicks 'OK' to dismiss the dialog, but now, the dialog has two outcomes: The user can answer 'Yes' or 'No'. This means there are two possible outcomes we must take into account.
confirm() does not only does something, but it also returns a value based on the outcome. In this case, the returned value is the answer on the question. The answer to this particular statement is either true or false. There's a special data type that can either be true or false: the boolean. While it doesn't seems useful at first hand, it can be used for lots of things: visible/invisible, success/failure, yes/no, solid/unsolid... confirm(), for example, returns a boolean.
Next, we check if the boolean is equal to true (the user wants a cookie). The script checks if the left side of the == is equal to it's right side. If that's true, the if-statement will be correct, and continue with the code in the directly following {} brackets. Here, we run another alert() telling the user to go look for his own cookies.
If the if-statement is incorrect, it will skip the first following {} brackets. But what if we still want to send a message to our user after he clicks incorrect? We catch him up by using the else-statement. The code in the {} brackets will be run when the if-statement right above it is false. If we had three or more choices in our dialog, the situation would be more complex, but since the user only has two options, and we know he didn't pick the first one, that must mean he picked the second one, so the else-statement is good to go.
In our last example, we'll get started with variables.
var amount = prompt("How many cookies are there in this jar?")
amount -= 1
alert("Wrong! I just ate a cookie, now there are only "+String(amount)+" left!")
We declare something being a variable by putting 'var' in front of it. We only need to do this once per variable. Also, while we declare it, we can also directly assign a value to it. We do this with the = sign. This will make the value to it's left side the same as the value on it's right side. So, if we would do 'var a = 3*2', the variable a would contain 6. Giving a value to a variable is called an assignment.
prompt() is the final evolution of the alert() and confirm() functions. It's nearly the same as the confirm() prompt, but now, the user has a text box in which he can enter a message himself. (Please not that in this case, we ask the user for a value (amount of cookies), but the user can also enter a string, or a negative number. Fixing this is not something within the scope of this introduction, although you can look it up if you're eager to know.)
After the user enters his value and clicks OK (when the user clicks cancel, amount will be set to zero), we will change the variable. -= will modify the variable to the left with the value to the right. In this case, we decrease amount by one (we take a cookie from the jar). You can also use +=, *=, /=, and more.
The third line of the code alerts the user of the correct amount of cookies. We now chain multiple strings together to a single string by first closing the string, entering a + symbol, and opening the new string. Since the value the user entered, is a number, we have to convert that number to a string first, and that is what the function String() takes care of. The text will display beautifully inside the alert().
What you can do with code, depends mainly on your language. For example, in C++, you'll need to do nearly everything by yourself. In engines like Game Maker, all mayor functions are already available so you can start working on actual game design in less time than you would need when having to start from scratch. I'll also note that almost every programming language can be expanded by code libraries. These mainly consist of code written in the same language, but since they're already written, they'll save you a lot of work you would need to program by yourself otherwise. For example, jQuery is a JavaScript library that makes certain (fairly) important features much more easy to use, with lesser code.
What I've just taken you through is the very base of coding. You can do this at a lot larger scale, with many functions and clearly structured code. In this Stack Overflow answer on a topic about computer jokes, you can see that code that essentially becomes more and more complex, while still doing the same thing (displaying Hello World on the screen). Practice with tiny things like these, and slowly but steadily you'll be able to bigger projects like games or engines. Good luck!
As a last note, anyone that wants to get into programming without diving too deep into code right away, then maybe Game Maker or Unity is of more use to you. I'll go deeper into this in the Game Development 101. Also, If you want to take a more in-depth look at the code which we digested above, you can visit this JSFiddle where you can edit and test it.