Before we begin our discussion on how to utilize LUAU, the programming language in Roblox, we will make sure that you are familiar with printing. Printing is just displaying what you want displayed as text in the output box.
To print, you can simply write,
print(WHAT_YOU_WANT_TO_PRINT)
where WHAT_YOU_WANT_TO_PRINT is exactly what it spells. This will display WHAT_YOU_WANT_TO_PRINT in the output box given that WHAT_YOU_WANT_TO_PRINT is a correct type.
Not everything you put inside the print will work. Later in this chapter, you will discover what will work and how to use printing for debugging. For example, only adding print(hello) will not work and will give you an error.
LUAU, the programming language used in Roblox, has variables which are stored pieces of memory.
You can think of a variable as a name given to a value you want to store. If you wanted to store the number 10 and you wanted to name the variable ten, you would simply write
local ten = 10
The "local" keyword indicates that the variable is a local variable which allows for extremely fast access and will be explained in later chapters.
Variables in LUAU do not have types, rather values have types. A type can simply be explained as what kind of memory you want to store. There are many different types in LUAU which will be explored in the next few sections.
LUAU consists of many different Values, including Integers, Strings, and Booleans.
Since different values are needed to store different types of data, the type of value used should be based on what type of data you are trying to store.
The next few sections will discuss the different types of basic values that exist in LUAU.
Integers are used to describe data in the form of numbers. Integers are especially useful because they can be used with many mathematical methods in order to manipulate them.
Integers can easily be stored in a variable by writing
local ten = 10
By writing the number "10" we indicate that the variable "ten" holds the number 10.
There are many mathematical methods we can use with integers including, "+", "-", "/", "*"
Therefore we can easily manipulate a variable containing an integer value.
Notice how we no longer use the keyword "local" after initializing the variable "num". This is because we only need to indicate the variable is a local variable in the beginning.
Boolean values are denoted as either being true or false.
These values are particularly powerful when used in conditional statements which we will go over in later chapters.
Boolean values can be written as:
local Value = true
where "Value" is the given name of the Variable and "true" indicates a true boolean value.
Additionally, the keyword "not" is often used with booleans to indicate the opposite of a value. For example, if our variable "Value" is initially set to true as above and we write
Value = not Value
the variable "Value" would be given the opposite boolean value of "false".
String values are denoted by including quotation marks around a group of characters. Strings are essentially a list of characters and are often used to store words.
For example, if you wanted to store a name you would use a string value. Let's say we wanted to store the name "David". We would write:
local name = "David"
The quotation marks indicate that we are storing a string. With strings, we can store any sequence of characters.
In the first section of this chapter, you learned that what you put inside a print matters and not everything will print. You can either print variables or values. For variables you would just write print(variable_name), where variable_name is the name of the variable.
When it comes to printing values, all values can be printed without special wrapping, except for strings. Strings require quotations to be placed around the word.