DrVulcan
|
  |
| Joined: 15 Jul 2013 |
| Total Posts: 320 |
|
|
| 05 Aug 2013 02:54 AM |
--> Detailed Tutorial to scripting ROBLOX Lua, this guide has been wrote by Water Aura (drvulcan) ----> Variables
Learning variables is the first step to starting Lua, we first have to find out the two different variables
- Global - Global variables are variables that can be called or used throughout the script.
- Example : a = true - Local - Local variables are variables that are scoped or can only be used to a certain enviroment (functions, events, and others) - Example : local a = true - Example 2 (Will print nil instead of true) : function Test() local a = true end Test() print(a) - In Example 2 the script will error due to the fact that the variable "a" is scoped to function "test" so variable "a" would still be considered nil
Variables can be defined to a certain values, but values are classified differently, certain values could be classified as (strings,booleans,userdata,table) :
- String - To be classified as a string, the value has to be surrounded by quotations (") or (') - Example : local a = "string" In this example we define "a" as a local variable and its value is equal to the string "true" - Booleans - To be classified as a boolean, the value has to be (true) or (false) - Example : local a = true - Example : local a = false - These two examples define "a" as either true or false and these booleans are used in arguments - Userdata - To be classified as userdata, the value has to be a object in ROBLOX (As far as you should know) - Example : -- In this example we have a "Part" in the workspace local part = workspace.Part In this example we define the variable part as a "Part" in the workspace - Tables - To be classified as a table, the value has to be in brackets - Example : local table = {"valueA","valueB"} - Example : local table = {true,false,true} - Example : local table = {workspace.Part} - In all these examples we can include every type of value inside of a table
----> Tables
As we learned in our last lesson tables are created in brackets, now we learn how to call the values - Setting Variables to a table - Example : local a = {} a.string = "randomstring" -- local b = {} b.randomvalue = "asd" - In this example we are setting a variable inside of table "a" and naming that variable "string", value is "randomstring" - Example 2 : local a = {} a[1] = true - In this example we are setting a variable inside of a table "a", that variable is in the position 1 inside the table to the boolean value true - Example 3 : local a = {} table.insert(a,"randomvalue") - In this example we are using a function "table.insert", this function makes it easier to insert a value into the table. - Function Arguments : table.insert(Table,Value) - Calling Variables from a table - Lets use print to see what the string is - Example : -- Lets say we set the variable with a name! (Setting Variables to a table, Example 1) local a = {} a.string = "randomstring" print(a.string) - In this example it would print "randomstring", so we called a.string!
|
|
|
| Report Abuse |
|
|
DrVulcan
|
  |
| Joined: 15 Jul 2013 |
| Total Posts: 320 |
|
| |
|
Qeenofpie
|
  |
| Joined: 12 Oct 2010 |
| Total Posts: 9995 |
|
| |
|
Kamiyama
|
  |
| Joined: 09 Jan 2013 |
| Total Posts: 8876 |
|
|
| 05 Aug 2013 02:55 AM |
instruction aren't clear enough, got rocket stuck up ass
and are you v.2 of me, or am i mistakened |
|
|
| Report Abuse |
|
|
| |
|
DrVulcan
|
  |
| Joined: 15 Jul 2013 |
| Total Posts: 320 |
|
| |
|
DrVulcan
|
  |
| Joined: 15 Jul 2013 |
| Total Posts: 320 |
|
| |
|
ProProfit
|
  |
| Joined: 13 Nov 2012 |
| Total Posts: 7678 |
|
| |
|
Kamiyama
|
  |
| Joined: 09 Jan 2013 |
| Total Posts: 8876 |
|
|
| 05 Aug 2013 02:58 AM |
dude u know ur just gonna get vulcan deleted too might as well send me a trade with all ur items to help me theres no running away, the mods hate u |
|
|
| Report Abuse |
|
|
ProProfit
|
  |
| Joined: 13 Nov 2012 |
| Total Posts: 7678 |
|
| |
|