generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Basic Lua Tutorial

Previous Thread :: Next Thread 
Jameson5011 is not online. Jameson5011
Joined: 11 Oct 2008
Total Posts: 24
21 Sep 2013 02:07 PM
Subject: Properties, Loops, and statements

Properties: Assuming you already know how to find things in game (game.Workspace.ect)
properties work the same way. To access a property simply access the thing you want to change (i.e. "Part")
- game.Workspace.Part
and then access a property of Part like so:
- game.Workspace.Part.Transparency
now change it!
- game.Workspace.Part.Transparency = .5
Note: Transparency can be any number between 1 and 0, 1 being invisible.
To find more properties of things you can open studio>Help>Object Browser and then click any object to find functions, properties and events that apply to it. (Properties are blue, functions purple, and events yellow)

Loops: Loops are mainly used to repeat something a given amount of times.
1) While Loop
This loop will repeat a piece of code infinetly "while" something you set is true, false, nil,ect.
Format: while (condition) == (bool value - true or false) do (stuff) wait() end
An important part of this loop is the wait()! Without it the entire game will crash; you can put how many seconds to wait in the () or just leave it blank to have it wait the min amount.
Ex) while game.Workspace.Jameson5011 do game.Workspace.Jameson5011.Humanoid.Health = 0 wait(5) end
-- this would loop kill me

2) For Loop
Format: for i = #,#,# do (stuff) end
The first # is the starting point, the 2nd the ending point, and the 3rd is how much it will count by. If you don't put a 3rd # then it will automatically be 0.
Ex) for i = 10,1,-1 do print(i) wait(1) end -- this would count down from 10
This is not to be confused with a pairs loop, which is more complex.

3) Pairs (or ipairs) loop
This is more advanced, so don't worry if you are completely lost.
Format: for index,value in ipairs(table) do (stuff) end
Ex) theTable = {1,2,"Hi there!",Vector3.new(5,5,5)}
for i,v in pairs(theTable) do print(v) end
-- this would print what was in the table; a table is simply a list of values if you were wondering.
-- the difference between pairs and ipairs is how it iterates (goes through) the table. For more details check out the wiki


Statements
1) repeat until
This is VERY similar to a while loop and is not oftenly used.
Format: repeat (thing) until (condition)
Ex) repeat kill() until game.Players.Jameson5011 == nil
This would repeat the function kill() (i made it up) until I wasn't in the game
This statement doesn't need a wait() or end

2) if statement
This is a common statement used to check a condition.
Simple Format: if (condition) then (do stuff) end
2nd Format: if (condtion) then (do stuff) else (do other stuff) end
3rd Format: if (condition) then (do stuff) elseif (condition) then (do other stuff) end
Ex1) if game.Players.Jameson5011 then print("Trouble's here") end
Ex2) if game.Players.Jameson5011 then game.Workspace:breakJoints() else print("all clear") end
Ex3) if game.Players.Jameson5011 then print("HEEEERREEE's JOOHNNY!!!") elseif game.Players.Johny then print("I'm actually Johny") end
Note: You can mix and match these various forms

3) Connection Statement
If you don't know what an event is, this may be kinda hard for you to understand.
-- basically it a set of conditions that the script will look for (if you tell it to)
Format: child.Event:connect(function)
Ex) game.Workspace.Part.Touched:connect(onTouch) -- no need for () after onTouch b/c it's being passed as an argument to :connect
I'd explain more about these but I'm in a bit of a time crunch; check out the wiki if you have any questions.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2013 02:16 PM
wrong forum
Report Abuse
SuperJediNinja is not online. SuperJediNinja
Joined: 28 May 2012
Total Posts: 4097
21 Sep 2013 03:55 PM
bump
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2013 03:55 PM
idiot above
Report Abuse
soupsoupsoup3 is not online. soupsoupsoup3
Joined: 31 Jul 2013
Total Posts: 219
21 Sep 2013 03:58 PM
"If you don't put a 3rd # then it will automatically be 0."

I think you meant 1. If it was zero it would not execute the loop at all
Report Abuse
SuperJediNinja is not online. SuperJediNinja
Joined: 28 May 2012
Total Posts: 4097
21 Sep 2013 04:38 PM
support lol jk
Report Abuse
SuperJediNinja is not online. SuperJediNinja
Joined: 28 May 2012
Total Posts: 4097
21 Sep 2013 04:38 PM
well im not joking so __-__
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
21 Sep 2013 04:52 PM
Awesome for beginner scripters.
Report Abuse
2unknown2 is not online. 2unknown2
Joined: 30 Oct 2011
Total Posts: 9351
21 Sep 2013 08:19 PM
Nice tutorial.
Report Abuse
BlueTaslem is not online. BlueTaslem
Joined: 11 May 2008
Total Posts: 11060
21 Sep 2013 08:46 PM
This is pretty terrible.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2013 08:51 PM
Why did you reply! :(
I thought it was going to die! :(
Report Abuse
stephen1182 is not online. stephen1182
Joined: 31 Aug 2010
Total Posts: 4003
21 Sep 2013 09:03 PM
This is pretty terrible.[2]
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2013 09:03 PM
Why did you reply! :([2]
I thought it was going to die! :([2]
Report Abuse
TaskScheduler is not online. TaskScheduler
Joined: 14 May 2013
Total Posts: 497
21 Sep 2013 09:03 PM
Although this is a tutorial that was well made, it has a few flaws.

1. There are numerous small grammatical mistakes.
2. 'Note: Transparency can be any number between 1 and 0, 1 being invisible. ' Did you mean, 'Note: Transparency's effective range is between 0 and 1. Anything equal to or greater than 1 is completely invisible, whereas anything equal to or less than 0 is completely opaque.'?
3. This isn't the correct forum to post this in.
Report Abuse
stephen1182 is not online. stephen1182
Joined: 31 Aug 2010
Total Posts: 4003
21 Sep 2013 09:06 PM
^ smart a-nevermind.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
21 Sep 2013 09:07 PM
4. It's stupid
5. It's dumb
Report Abuse
dbo12 is not online. dbo12
Joined: 06 Feb 2010
Total Posts: 600
21 Sep 2013 09:10 PM
Dead
========
Below is an idiot and leaving scripters
Report Abuse
SuperJediNinja is not online. SuperJediNinja
Joined: 28 May 2012
Total Posts: 4097
21 Sep 2013 11:30 PM
He was in a rush give him a break...
Report Abuse
flatline115alt is not online. flatline115alt
Joined: 03 Aug 2013
Total Posts: 537
22 Sep 2013 02:22 AM
This was bad. This wouldn't help anybody except if they wanted to be confused.
Report Abuse
2unknown2 is not online. 2unknown2
Joined: 30 Oct 2011
Total Posts: 9351
22 Sep 2013 09:25 AM
Move this to SH.
Report Abuse
flatline115alt is not online. flatline115alt
Joined: 03 Aug 2013
Total Posts: 537
22 Sep 2013 09:58 AM
Move this to SH.
----------
"Anything about scripting that is not a help request or topic belongs here." - Scripters Sub-Forum description.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image