Variable Basics(
Variable Basics (Updated) | Godot GDScript Tutorial | Ep 1.1 ):
● Variable is a container that contains a value
● To write a variable type var followed by a unique name:
var uniqueName ( = Literal value/Data Object)
○ Everything written in yellow is mandatory and
everything in the () is optional
● Variables cannot have a name that already exists in a script
● You can leave a variable empty or assign it a literal value or
a data object which is represented by =
● Written examples 2
○ var playerHealth = 100
Named playerHealth and assigned (=) a literal value of
100
○ var playerHealth
No value will auto assign null
● Typed variables are explicitly declared using : followed by
data type
○ Examples:
■ Var lifePoints: int = 100
■ Var lifePoints: int
● Declaring data types on variables is usually good practice as
ot leaves less room for confusion on the purpose of the
specific variable
● Assigning a value that is not a declared type will throw an
error
● Common data types with typed variables:
○ var aNumber := 10
○ var aBoolean := true
○ var aString := ‘hi friend’
○ var aFloat := -12.0
● In GDScript you may also assign an object that is the
subtype of the class type
○ var my_node2D: Node2D = $Sprite as Node2D
● When to use variables:
○ You should use variables when you have data that
needs to change over the lifetime of the game/program
■ Var playerHealth = 100 ( value of health may
change)
Life Cycle & Refrence Counting (
Life Cycle & Reference Counting | Godot GDScript Tutorial | …
)
● Memory life cycle is the time between an objects
creation and destruction
Allocate Memory
● Memory is allocated by the operating system which allows
your program to use it
● All computers have memory also known as ram
● Memory can be thought of us bytes
Use Memory
● read/write memory operations are happening as you are
using the allocated memory
● Assigning and changing variable values in your script/code
Release Memory
● When variable(s) are no longer in use release the entire
memory so that it is freed and can be used to allocate new
memory
● *Dependds on the programming language you are using
whethe this is done manually or automatically
General Tip for Memory
● The less memory you use the better in general
● For games using less memory takes into consideration the
performance for users who are using lower size rams in
computers
Going over Allocacted Memory
● If there is enough space the os will allocate more memory
from ram to your app/game
● If you go over the ram limit the os will start allocating
memory to the hdd/sdd
● Using hdd/sdd for memory is slower than using ram
Basic Variable Process
● var x = 2020
○ Allocate enough memory for the variable in this case
enough memory to hold an int
○ Assign the value 2020 to that memory address location
○ Indicate that x points to that value
○ Depending on the language memory is freed when not
in use
●
●
●
● Godot version
●
GDScript tip for memory management
● Nodes are not referenced counted in the engine
● This means that removing a node from the tree will not
delete it (remove_child)
● To better manage nodes, create a pool of objects and re-use
the node object
● You can also explicitly destroy/free the node from memory by
calling “queue_free()” in the “_exit_tree()” which is called
when the node is removed from the tree
Operators & Operands (
Operators & Operands | Godot GDScript Tutorial | Ep 02 )
Operands
● Operands are numerical, text, and boolean values that
a program can manipulate
● Operands can also be object values
● 1 + 2 (operands are 1 and 2)
● X - y (operands are x and y
Operators
● Operators are symbols used to manipulate and check
operand values
● 10 + 20 (operators are +)
● X -1 (operators are -)
Assignment Operators pt.1
● Assignment operators assign a value to its left operand
based on the value of its right operand/ the simple
assignment operator is = which assigns the value of its right
operand to its left operand
● X = y ( assignment)
Comparison Operators
● A comparison operator compares its operands and returns a
logical value based on whether the comparison is true
● To see if 2 operands are equal use the equal operator (==)
● To see if 2 operands are not equal use the not equal
operator ( !=)
● To see if the left operand is greater than the right operand
use the greater than operator pointing to the right ( >)
● To see if the right operand is greater than the left operand
use the greater than operator pointing to the left (<)
● To see if the left operand is greater than or equal to the right
operand use the greater than or equal to operator pointing
toi the right (>=)
● Opposite the top note (<=)
Logical Operators
● GDScript has 3 logical operators
● &&, ||, !
&&
● The logical AND operator is denoted by the 2 && or the word
“and”
● It will return fals as long as any of the operands can be
converted to false starting from the left most operand