These are mostly used in calculations, comparisons, and operations on binary bits.

They are evaluated in order of importance (precedence).

For example, in a calculation: times (x) takes precedence over plus (+) so 2 + 3 x 2 equals 8 rather than 10. A good calculator should obey this precedence rule. For an exercise: check it on your smartphone calculator app.

The following tables list operators with the highest precedence first.

Mathematical Operators

One good use for this operator (otherwise known as the modulo operator) is to limit the range of a counter value. If the divisor is n, then the counter will count between 0 and n - 1, rolling back to zero on each multiple of n. Look forward to a code example using this concept later in the tutorial series.

Some assignment shortcuts are available as follows (these have the lowest precedence over anything - as you might assume given that they are accepting the result of a prior evaluation):

These are the comparison, and logical operators that are mainly used in if statements.

The result of a boolean operation is true or false.

Example: x = 3 > 4 or 5 < 6 # x == true

Bitwise Operators

Note: bitwise operators are not likely to be used very often unless you are doing something quite technical involving bit manipulation.

Every number or character is comprised of binary bits so we are able to flip bits, shift bits, mask bits etc. Individual bits are zeros and ones. They are set or reset according to logical operations related to how digital logic gates operate.

The first bit is called the LSB (Least Significant Bit) and the last bit is called the MSB (Most Significant Bit). Numbers constructed from zero/one bits are binary numbers.

Counting in binary goes like this: 0 1 10 11 100 101 110 111 1000 …

However, in the editor, we only see decimal equivalent numbers. So you will need to imagine the binary equivalent of 8 is 1000.

For an exercise: use the programmer’s calculator in Windows (or the equivalent app in your OS) to get used to fooling around with binary numbers.

We covered Math, Boolean, and Bitwise operators in order of usefulness, and hence importance to understand. Some GDScript operators have been left out of this section since they are part of more advanced topics to be introduced later, so look forward to them in later tutorials!

Next: Functions

Support this website by checking out my Itch.io page