Programming Crash Course

From Bitfighter


Introduction

While scripting in Bitfighter is meant to be as simple as possible, one can not escape the fact that you are writing a computer program. In order to learn, read, or speak about programming, you have to understand the basic concepts and vocabulary that all programmers use.

This page is meant to be a light introduction to programming concepts as they apply to Bitfighter scripting.

What is a Program?

People say that computers "speak in ones and zeroes". This is only half true. Humans don't speak ones and zeroes, and computers can only do what a human has told them how to do. For that reason we need a language that both humans and computers can understand, somewhere in between human languages like English and the computer languages of zeroes and ones. We call these "programming languages".

A "program" or "script" is a file written in a programming language by a human, and which is meant to be run by a computer.

A script is run from top to bottom, just like humans normally read. The computer reads one line at a time, and runs each line as it comes to it.

Variables

A variable in programming is related to variables in math. They are used to hold values. Here is a simple example of creating a variable called x and "assigning" it a value of 1:

x = 1

Like in math, we can perform arithmetic on variables, and use them to set the value of other variables:

x = 1
y = x + 2

After this program has run, y will have a value of 3, which is equal to 1 + 2

Unlike in math, variables in programming can hold things other than numbers. They can hold pieces of text, which are called "strings". In Bitfighter, they can also hold objects, such as a Flag or a Ship. These topics are discussed more in the tutorials.

Functions

If you think of variables as the "nouns" of programming languages, then functions are the "verbs". Lets expand on our example above:

x = 1
y = x + 2
print(x)
print(y)

print is a function. When we say print(x) we're saying to the computer "print the value of x". In Bitfighter, this will show up on the Console (press Ctrl+/ in-game to see it).

TODO: function definitions, arguments, return values