a Beginners guide to Lua – 5.1 (roblox lua)
(if your thinking, what has lua been used to do, world of warcraft is written in lua =))
Lua. It’s a fast and powerful little language and I found it fairly easy to learn. In this Article we will be using software called roblox. they use a slightly modified version of Lua 5.1 and it is very easy to use. Lua is not originally Object oriented but roblox made it so.
First things first, You will need to download Roblox. This can be downloaded at www.roblox.com. Don’t worry. No viruses and believe me you will like this game/code editor (yeah it comes with thousands of games free) Any way once your have it downloaded open up the roblox studio and you will see the front page of the roblox website.
Click the new icon on the tool bar or go to file | new. You should see a blank map waiting for you to build on it. You can mess around with the bricks (which remind me of legos) or we can get started.
I know the view is stunning but lets clutter up the screen (don’t worry these tools are useful) Go to View | Explorer, View | Properties, and View | Output if they pop up as new windows (output shouldn’t) then drag them to the right/left side of the screen and a cross should appear. Put on on the top and one on the bottom and it will be fine.
In the toolbar, go to Insert | Object and select “Script” (the list is in alphabetical order) Double click it in the list and you should see a new object pop up in the explorer tree named ‘Script”. Double click on the new script and a text editor should take the place of the lovely clouds. You’ll probably notice that someone has already written in your script. if you were to g back to the workspace (the graphic part of the studio), and clicked the play button at the top right corner of the screen and glanced down to the out put there would be a “Hello World” there.
Why? Well retrun to the script and look. print(”Hello World!”) this is the first script anyone learns in any language is the Hello World Script. In lua’s case the script uses a built in function called print(p). Let’s go into detail.
print(p). the print function is used to print things to the output box. the p between the parenthases is the one parameter of the function. whatever is in between the parenthases represents p and is then printed when the script is run.
You may have noticed that the Hello World was in quotes (print(”Hello World”)). When something is in quotes this is called a string. it is just text. (ex. “1″ “Hi”) You can store numbers in a string but there is no need to. Try replacing “Hello World with 1 and run it. It prints a 1. you dont have to quote it because it is a number. There are two main types of numbers. an integer (a whole number) and a Double (any number).put 1 + 1 in a print() function and see what happens. That’s right. 1 + 1 = 2 and it printed two.
Now there are variables too. in a line above print(”Hello World”) type in x = 1. we’ve just set x as a integer variable and now we can use x in our function. type print(x + 1) and then you get… 2. so you can use variables in our scripts to math things like math and displaying messages alot easier.
Well done! You’ve made your first script in Lua 5.1. If your hungry for more then there will be a sequel to this guide and there is also help on the roblox wiki (wiki.roblox.com) happy programming!!!