Hello and welcome to the GDScript fundamental tutorial series.
In this episode, I go over data types and literal values in Godot GDScript.
Even though this is a more advanced topic, try your best to understand data types and literal values. Game programming is all about manipulating literal values.
In programming, a literal is a value directly written in the source code instead of being the result of some other expression (such as referencing a variable or a constant).
Think of a literal as something you ‘literally’ provide in your script.
A data type is an attribute of data that tells the compiler/interpreter how the programmer intends to use the data.
Data types define the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored.
Some common data types include Strings
, Numbers/Integers
, Floats
, Booleans
, and Null
Strings are a data type used in programming to represent text rather than numbers.
It is comprised of a set of characters that can contain spaces and numbers.
A string value is denoted by values inside the double quotation symbols " "
.
"Hello World"
is a string value.
"I have 0 cats!"
is a string value.
"100"
is a string value.
"true"
is a string value.
"Null"
is a string value.
One thing to keep in mind is that you cannot do numerical calculations with string values.
"1" + "1"
(strings) in programming is not the same as 1 + 1
(integers).
"1" + "1"
will become the string value "11"
whereas 1 + 1
will become the integer value 2.
An integer is a data type that represents some range of whole mathematical numbers.
In Godot GDScript, this range is between the values -9223372036854775808
and 9223372036854775807
.
Integers are whole numbers. Some examples of whole numbers include 0
, -100
, 911
.
Integers can be both positive, negative, and the number zero.
The most important aspect of an integer value is that it cannot have a decimal point (.
).
If there is a decimal point in the number, then it is a float data type value.
A float s a floating-point number, which means it is a number with a decimal point.
Float data types are used when precision in mathematical calculations are needed.
A float value is similar to an integer. It is a numerical value; the only difference is that a float value is a decimal number.
Some examples include 0.0
, -100.0
, and 911.0
.
Notice that the only difference here versus their integer counterpart is the decimal point.
If it’s a whole number, then it’s an integer. If it has a decimal point, then it’s a float data type.
The boolean is a data type that has only one of two possible values.
Boolean values are denoted by the keywords true
and false
.
The keyword true
numerically represent the values 1
,
while the keyword false
numerically represents the value 0
.
The null data type is used to represent the absence of data.
The null value is denoted by the keyword null
.
In GDScript, null is an empty data type that contains no information and cannot be assigned any other value.