Hello and welcome to the GDScript fundamental tutorial series.
In this episode, I go over operator & operands in Godot GDScript.
Operators allow you to “operate on” or manipulate variables/constants.
Operators are symbols (=
, <
, +
, etc) that instruct the program to perform a task.
An operand is a variable, constant, or expression that acts upon the operator.
var a = 1 + 2
In this example, the integers 1
and 2
are operands. The +
symbol is the operator.
The operator instructs the program to add the numbers 1 and 2 together.
On top of that, the =
symbol is the assignment operator. It instructs everything to the left of the symbol
to be assigned to the variable on the left side of the =
.
Operators | Description |
---|---|
+ | Addition Operator |
- | Subtraction Operator |
* | Multiplication Operator |
/ | Division Operator |
These operators are self-explanatory.
You will add, subtract, multiply, and divide operands together.
1 + 2 # addition operand
1 - 2 # subtraction operand
1 * 2 # multiplication operand
1 / 2 # division operand
Relational operators are used when you want to compare operands.
Operators | Description |
---|---|
== | Equal to operator |
!= | Not equal to operator |
> | Greater than operator |
>= | Greater than or equal to operator |
< | Less than operator |
<= | Less than or equal to operator |
When using relational operators, the value returned to you is a boolean value true/false
.
If the relational statement is satisfied (if it is true), then a true
value is returned.
If a relational operator is not satisfied (if it is false), then a value of false
is returned.
1 == 2 # returns false
1 != 2 # returns true
1 > 2 # returns false
1 >= 2 # returns false
1 < 2 # returns true
1 <= 2 # returns true
Keep in mind the values returned from the greater/less than operator.
2 > 2 # returns false
2 < 2 # returns false
2 >= 2 # returns true
2 <= 2 # returns true
Logical operators are used when you want to compare the truth/false values of an operand.
You will usually use logical operators inside of if statements and while loops.
Operators | Description |
---|---|
&& (AND) | AND Operator |
|| (OR) | OR Operator |
! (NOT) | NOT Operator |
&&
operator to check if two operands are true||
operator to check if one out of two operands are true!
operator to check if the operand is falsetrue && true # returns true
false && true # returns false
false || true # returns true
false || false # returns true
!false # returns true
!true # returns false
Operators & Operands | Godot GDScript Tutorial | Ep 02 video & article by Godot Tutorials is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License .