A script is a series of instructions for a program to follow to create custom behavior. In order to give these instructions, you must provide the instruction in words the program can understand. ROBLOX uses a language called Lua to communicate these instructions. In this set of tutorials, we will go over the basic instructions you can use in ROBLOX Studio to create games.
To get started, we need to open the Output and Command Bar panels. To do this, click on the View tab and then on both the Output and Command Bar buttons.
The Command Bar shows up at the bottom of Studio by default, and is a place where we can write instructions for the game. The Output window will show any kind of text responses from the game.
The first instruction, or function, we will cover is called print, which makes text appear in the Output window. In the Command Bar, type:
After you are done typing, hit enter. The Output panel will show both the instruction and the message we wanted to print:
> print("Hello world!") Hello world!
print will output whatever is in between the parenthesis () that follow it. In this case, we printed out the sentence: Hello world!. When you want to print out sentences, which in Lua are called strings, you have to surround the sentence with quotations.
We can print other things, like numbers:
> print(7) 7
Notice how we did not put 7 inside of quotation marks "". If we are printing out a number and not a string, we do not need to include the "".
We can also print out the result of mathematical operations. For example, if we want to print the result of adding two numbers, all we have to do is:
> print(7 + 3) 10
We print all kinds of operations:
> print(10 + 5) 15 > print(10 - 5) 5 > print(10 * 5) 50 > print(10 / 5) 2
In scripting we often want to store information to be used later. We can do this by using variables. You can think of a variable as a box you put information in. To create a variable, all we need to do is give it a name and assign a value to it. For example:
> myFavoriteNumber = 7
The above line of code stores the number 7 into a variable called myFavoriteNumber. Notice how nothing is added in the output after we enter the above line. That is because the print function was not used. If we want to see what is stored inside of myFavoriteNumber we can put it inside a print function like this:
> print(myFavoriteNumber) 7
Like print, variables also work with mathematical operations and can store the results for future use:
> theSum = 5 + 6 > print(theSum) 11
We can also store strings inside of variables. Just like when we printed strings before, the string has to be surrounded by quotation marks "".
> myFavoriteAnimal = "Dog" > print(myFavoriteAnimal) Dog
We can give variables almost any name we want. There are a few rules one has to follow in Lua though when naming variables though:
In the next tutorial we will cover creating parts and changing properties through code.