User:JulienDethurens/Guide/Chapter 1

From Legacy Roblox Wiki
Revision as of 09:59, 22 January 2012 by >JulienDethurens (Created page with "Note: considering we are not yet in the ROBLOX-specific section, you can use the [http://www.lua.org/demo.html Lua demo], on the [http://www.lua.org official Lua website]. You...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Note: considering we are not yet in the ROBLOX-specific section, you can use the Lua demo, on the official Lua website. You can use it to run code. However, note that it uses Lua 5.2 and that ROBLOX uses Lua 5.1. Therefore, some of the things I will teach you will not work with it. Don't worry, though, almost everything still works in Lua 5.2. And I'll try to tell you whenever something I am talking about is no longer available in Lua 5.2.

I suggest using the Lua demo to test code, as it avoids you the trouble of starting the studio and everything. But you can also use the studio if you want.

Syntax

First of all, what is syntax? What does that word mean? Well, syntax is actually like grammar, but for a programming language. It explains how you must structure your scripts.

ROBLOX Lua uses exactly the same syntax as Lua. Only functions were edited and added, as well as removed, but the syntax is exactly the same. You can find the syntax of Lua in extended BNF here, except I promise you won't understand anything: The Complete Syntax of Lua.

Don't worry, though, you're not going to have to understand any of that. It's extended BNF, which doesn't really have anything to do with what you'll need to learn.

Names

Names, in Lua, are also called identifiers. They can be any text composed of letters, digits, and underscores and not beginning with a digit. They are used to name variables and table fields (you'll know what both of these are later).

Here are some valid names:

name
hello
_
_tomatoes
me41
_thisIs_StillaValid23name

Here are some invalid names:

2hello
th$i
hel!o
563text
82_something

Also, the following keywords are reserved by Lua and can not be used as names:

and       break     do        else      elseif
end       false     for       function  if
in        local     nil       not       or
repeat    return    then      true      until     while

When naming a variable or a table field, you must choose a valid name for it. It must therefore start with a letter or an underscore and only contain letters, underscores and digits.