User:SoulStealer9875/Programming With Lua: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>SoulStealer9875
No edit summary
>SoulStealer9875
No edit summary
Line 64: Line 64:


[[Image:Warning.png]] - Do not type Print instead of print, this will break your code! It's print, with the lowercase 'p'.
[[Image:Warning.png]] - Do not type Print instead of print, this will break your code! It's print, with the lowercase 'p'.
You can also print arithmetic's such as followed:
print(2+2)
Would output: 4
print(2-2)
Would output: 0
print(2*2)
Would output: 4
You can use this to do your math homework!
print(16+(((2*9)/1)*6)%2)
Would output: 16

Revision as of 13:13, 4 September 2011

Introduction

What's your story?

  • Are you the kind of person who wants to produce your own code?
  • Do you want to understand Lua code?
  • Are you someone who wants to know how code talks to the computer?


Well, if you want to write Lua code - I suggest you read this whole guide. This guide avoids the "of-course-you-already-know" assumption and describes Lua programming from scratch.

Icons used in this guide

- Tip. I use this when I want you to have some extra information; something helpful that will make you a bit more aware with coding in Lua.

- Warning. I use this when fiddly things come about. Things you may forget. For example, if I think you may capitalize a letter that may cause your script to break. I will use this icon.

Part 1

Chapter 1: Getting Ready

There's a few things you need to do before you start learning how to code in Lua. The first thing is to get ROBLOX Studio. If you don't already have this software, click here.

When you've downloaded ROBLOX Studio, or if you already have the official ROBLOX Software, click 'Start' -> All Programs -> Roblox -> ROBLOX Studio. This will open the software taking you into ROBLOX Studio.

When ROBLOX Studio finishes loading you will find a toolbar at the top. Find 'File' -> New. Selecting new will open up a new place, you will be required to use this while you read this guide.

Next, we need to insert a blank script. To do this, find 'Insert' in the toolbar -> Object. Selecting object will open up a dialog window with several objects you can insert into your game. Scroll around the dialog window until you find 'Script' then select OK.

If you don't already have the Explorer panel open, go to 'View' in the toolbar -> Explorer.

In the explorer panel, find '+ Workspace'. Press the + next to workspace then double click on 'Script'.

After double clicking on Script, you will be taken into a blank white window displaying the text by default: "print 'Hello World'". Highlight that text and delete it.

Exit out of the script's window and go to 'View' in the toolbar -> Output. This opens up the output window. This will come handy in later chapters when we learn to display text on it.

Chapter 2: Printing

Everyone knows social life is important, so why not be social to the computer? With Lua, and any other programming language, we can talk to the computer. Not literary, 'talk' to the computer. More like, allow the Lua programming language to turn the code into binary and send it to the system which reads the binary and does what's it told to do. Here's a diagram of how it works:




The diagram towards the left shows the input, this is the code that you type in. It is then turned into binary and sent off to the system. The system reads the binary code and executes it, otherwise known as the output.


Open up the script you inserted earlier. Before we deleted the default text which was "print 'Hello World'", if we were to run the script with the text on it and you had the output window open, the text "Hello World" would be displayed in it.

How is this? This is because the function "print" is executed and the text inside the quotation marks are displayed in the output window. This is called "printing text". There are other ways of printing text such as followed:

print('Hello World')
print("Hello World")
print [[Hello World]]
print([[Hello World]])
print "Hello World"

and so on.

Some people write a semicolon after these, but it doesn't make any difference; so don't worry about that.

- Do not type Print instead of print, this will break your code! It's print, with the lowercase 'p'.

You can also print arithmetic's such as followed:

print(2+2)

Would output: 4

print(2-2)

Would output: 0

print(2*2)

Would output: 4

You can use this to do your math homework!

print(16+(((2*9)/1)*6)%2)

Would output: 16