User:JulienDethurens/Guide/Introduction

This introduction will introduce you to scripting, by telling you the basics. You will not really learn any syntax or anything like that in this section, you will just learn some important informations about scripting.

Scripting

So you want to learn scripting. After all, that's the reason you're here, right? But, first of all, what is scripting? You probably already know it, but I'm still going to explain it.

Scripting means the same thing as programming. It is used to tell your computer what you want to do. In this case, since we're on ROBLOX, we use ROBLOX Lua, a modified version of Lua, to interact with the ROBLOX API and create awesome places for other users to play.

When you create your place, you have a vast choice of objects to use to do many things. All of these objects can do different things, and they can all be manipulated by scripting, which makes it possible to do even more things. And this is precisely what you're going to learn: how to use scripting to make your places better.

ROBLOX Lua, like every programming language, has a syntax, and libraries. In fact, pretty much everything there is in a language is its syntax and its libraries. By libraries, in this case, I mean built-in functions and libraries. C++ has a syntax, and offers built-in functions and libraries. C has a syntax and offers built-in functions and libraries. Java has a syntax, and offers built-in functions and libraries. And ROBLOX Lua, too, has a syntax and offers built-in function and libraries. However, unlike C++, C and Java, ROBLOX Lua is an embedded programming language, which means it is embedded in an application. This application is ROBLOX itself.

But, what is a programming language, you might ask? Well, a programming language is a language, just like English. It's just that it is used to talk with a computer, not to talk with humans. And, you see, computers don't have a brain that can think like ours, so you're going to have problems communicating with them. They won't understand what you tell them unless you say it in a specific way.

Lua

Lua is the language ROBLOX Lua is based on. It is a powerful, fast, lightweight and embeddable scripting language.

Because a lot of people make the mistake of writing it "LUA", I am going to explain some things about it. Actually, I'm going to do better. I'm going to let the creators of Lua explain it themselves:

"Lua" (pronounced LOO-ah) means "Moon" in Portuguese. As such, it is neither an acronym nor an abbreviation, but a noun. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

I strongly recommend reading this page to learn more about Lua. It explains many things about Lua which might be interesting to know.

Scripts

To script, you will need to use… scripts! You probably already know how to insert a script, but, if you don't, don't worry, I'll explain it here.

To create a script, first, you must open Roblox Studio. To do this, the simplest way is to go in the start menu, click 'All programs', choose the Roblox folder and choose 'Roblox Studio'. A window should appear with a browser and many buttons, toolbars and panels you might or might now know about. From there, just press CTRL+N, or go in the File menu and choose 'New'. It will open a place. From there, you can do lots of things. If you've never used the studio before, you'll find all these buttons everywhere confusing. If you're a builder, you'll find it a lot less confusing, though. But, don't worry, in both cases, I'll tell you what to do, so you don't get lost.

Inserting a script is simple. Just go in the Insert menu and choose 'Object…'. A window with a list of objects will appear. One of the object is called 'Script'. Select it and click 'OK'.

The script will be put in the Workspace, in the explorer. If you don't see the explorer, go in View and choose 'Explorer'.

I know I'm explaining everything, and you might already be used to the studio, but I'm still going to continue explaining everything for a while, because not everyone has used the studio before. Don't skip a section, even if you think you already know everything it contains, because it might still teach you something.

You have a script. That's nice, and all, but, what to do with this script? Well, to edit a script, you first need to open it, which can be done by double clicking it. So double click the script in the explorer.

Then, the script editor will appear. It lets you edit your scripts. Personally, I use an external editor, because I don't like the built-in script editor, but since you're beginning, you should just use the built-in script editor. I'll explain more about external script editors and other subjects at the end of the book, in the miscellaneous section. You can read that section at any moment, by the way. You don't need to wait until the end to read it. It contains informations that could be useful and that do not necessarily require to have read all the book to understand.

Hello world

Right now, the script editor should only contain one lin:

print 'Hello world!'

You might wonder what that does. It actually shows 'Hello world!' in the output when you run the game. You can run the game by going back to the studio view (choose 'Place1' or something similar in the tabs list) or by closing the script editor (click the x button in the top-right corner). Once back in the studio view, just click the green arrow (which should be on one of your toolbar) and all scripts will run. However, to see the result of the default script, you first need to open the output. Just go in View > Output to open it, and then click the pause button (next to the run button) and click the run button again, to re-run the game. The message 'Hello world!' should appear in your output.

To go in a little more detail, that code runs the print function with 'Hello world!' as argument. However, we'll talk about all of that later.

Script editor

Let's talk a little more about the script editor. Go back into it by double clicking the script again or by going back to its tab if you didn't close it. The script editor has many nice features that I should talk about.

Search

First, there is the search. You can search for something in a script by pressing CTRL+F. It will bring up a window which lets you search for something in your script. This will probably be really useful to you later when writing big scripts, to find something quickly.

Replace

Then, there is the replace window. Or sometimes called "Search&Replace". It allows you to replace a certain text by another text, which can be useful, for example, to replace all the occurences of the word 'dog' in a document by the word 'sky'. You can access it by pressing CTRL+H.

Markers

There are also markers. You can mark a certain line of your scripts by using a marker. There are many options for markers, all accessible by going in Edit > Script. You will see some options about markers such as "Add a Marker" and "Find Next Marker". They can be useful to mark a certain line on your script to be able to find it easily later. Personally, I use an external editor, so I don't use these. And, even if I used the built-in script editor, I dislike how markers don't have any shorcut, as that makes them complicated to use (you need to go in the edit menu everytime, etc..).

Script performance

The studio has a tool called the script performance panel. You can open it by going in the View menu and choosing "Scripts".

The script performance panel will then show. It allows you to know the performance of any of your script.

It contains 4 columns. The first contains the name of the script. Sometimes, this will be "[Unknown]". Just ignore these. What you actually care about is your own scripts, and these are just CoreScripts used by ROBLOX or scripts that were removed.

The second column is the count of these scripts. It counts all the scripts with a certain name.

The third column shows the activity of the script. You should be able to figure this out by yourself easily by playing with it.

Then, there is the rare. You should be able to figure out how it works by playing with it a little, just like the activity column.

The script performance panel can be useful to measure how fast your scripts run. Most of the time, it will not really be of any use, but there are some cases where it can make your life easier and make you not need to run complicated tests to measure the performance of your scripts.

Terminology

While reading this guide, you might encounter certain words you don't understand. I listed some of them here, even though the list is far from complete.

Note: all the terms listed here are defined in the context of this guide, and as used in this guide. For more complete definitions that are not based on this guide, look at an online dictionary.

Terminology
A set of terms, generally relating to a specific subject, in this case, scripting.
Code
A script or a part of a script, program, or any other executable. Considering this is a guide about ROBLOX Lua, generally a Lua snippet.
Array
An ordered list of values. In Lua, a table containing only numerical indexes.
Expression
A piece of code that returns a value and that can be evaluated.
Character
A symbol, letter or number that is used to form text or strings.
Syntax
Like grammar, but for a programming language. It is the way you must structure your code.
Studio
The Roblox Studio, accessible from the start menu.
Previous: Table of contentsNext: Chapter 1