|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
|
| 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 |
|
|
| |
|
|
| 21 Sep 2013 04:38 PM |
| well im not joking so __-__ |
|
|
| Report Abuse |
|
|
|
| 21 Sep 2013 04:52 PM |
| Awesome for beginner scripters. |
|
|
| Report Abuse |
|
|
2unknown2
|
  |
| Joined: 30 Oct 2011 |
| Total Posts: 9351 |
|
| |
|
| |
|
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 |
|
|
|
| 21 Sep 2013 09:03 PM |
| This is pretty terrible.[2] |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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 |
|
|
| |
|
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
|
  |
| Joined: 06 Feb 2010 |
| Total Posts: 600 |
|
|
| 21 Sep 2013 09:10 PM |
Dead ======== Below is an idiot and leaving scripters
|
|
|
| Report Abuse |
|
|
|
| 21 Sep 2013 11:30 PM |
| He was in a rush give him a break... |
|
|
| Report Abuse |
|
|
|
| 22 Sep 2013 02:22 AM |
| This was bad. This wouldn't help anybody except if they wanted to be confused. |
|
|
| Report Abuse |
|
|
2unknown2
|
  |
| Joined: 30 Oct 2011 |
| Total Posts: 9351 |
|
| |
|
|
| 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 |
|
|