More Lua Tips

Coding only works if it is typed properly. You don’t need to memorize every function or code, but there are a few things to remember.

Color Coding

If you haven’t noticed, Roblox colors certain words.

Blue are words in lua that cannot change and must be written properly like:

function, true, if, false, end, print

You will type these a lot!

Purple designates strings:

print ( “This is a string.”)

Comments are green. –This is a comment.

All of this will help you read your code quicker and easier.

Lua is Case Sensitive

Capitalizing letters is important in most programming languages.

This code is two variables:

dogs = 1
Dogs = 2

Lua sees them as two different variables.

Sometimes you will want to name a variable with two words like “big dogs.” The problem is that Lua does not accept spaces in variables, it must be one word. That is why we use camelCase. You simply capitalize the second word so you can read it easy while using two words.

Code Types

Just as an overview of the last few activities, you will see there are a few types of commands you can use:

  • Built-in functions like print, script, wait
  • Your custom functions like yellOof( )
  • Event triggers like Touched
  • Methods like connect and FindFirstChild

A good portion of your code will be one of these four kinds of commands.

= and ==

The = sign is used two ways in Lua.

One = means to SET a variable equal to something.

Two == means to CHECK if a variable is equal to something.

For example, this code is making a cat cute and then checking if dog is cute:

cat = cute
if dog == cute

Making Notes

Sometimes your code can get really long. You may want to title sections or make notes but you will break the code if you just write a sentence. This is how you make a note in Lua:

--[[ This is a comment --]]

You can use comment brackets like this to make multiple line comments or turn off entire sections of code (by making them comments instead)

--[[ This is one comment 
This is another comment--]]

If you want to just add a comment next to a line of code, you can do this:

function attack() --this code doesn't work yet

Comments turn green on the Roblox Script window.