| Top posting users this month | |
| | | Author | Message |
|---|
naknak Administrator


Posts: 855 Join date: 2010-07-30
 | Subject: Loops, loops, loops.... January 21st 2011, 5:32 pm | |
| In this I will show you examples of all the kinds of loops RBX.lua has to offer. While-do While-do, more commonly known as while true do, is one of the most used loops. The reason being is that most scripters on Roblox only know about it, no other loops. The way to use this loop is to put something in between while and do. If whatever is in between the two is true, then it will continue. You must end the loop with an 'end' | Code: | while true do wait() print("Hello World") end |
Repeat-until
Repeat-until is another loop in RBX.lua. It repeats itself until its requirement is fulfilled.
| Code: | repeat wait() print("Hello World") until 1 ~= 1 |
for-do
I use this to repeat something a specific amount of times, like if I wanted to make a script that counted down until it printed 'hi'
| Code: | for i = 10,1,-1 do print(i.. " second(s) until I print hi") wait(1) end print("hi") |
pairs loop
One of the more complex loops. This is used to run through an array and interact with its contents. 'i' is the number the script is on, 'v' is the object itself:
| Code: | m = {"cookie","Milk","Cake") for i,v in pairs(m) do if v == "cookie" then print("I ate my " ..v) end end |
Last edited by naknak on March 5th 2011, 4:58 pm; edited 1 time in total |
|  | | raboy117 Moderator


Posts: 75 Join date: 2011-01-19 Age: 14 Location: Canada, PEI, Charlottetown
 | Subject: Re: Loops, loops, loops.... January 21st 2011, 5:34 pm | |
| The only code i get is while true do i dont quite get 'for i = 10,1,-1 do print(i.. " second(s) until I print hi") wait(1) end print("hi")'
_________________ Site Hunter, Moderator.
|
|  | | blueymaddog Administrator


Posts: 1108 Join date: 2010-12-09 Age: 13
 | Subject: Re: Loops, loops, loops.... January 26th 2011, 5:17 am | |
| you should change While-do to while loops and For-do for loops. pairs is just a method of indexing through tables. watch me put caps in certain words of this line using pairs:
FOR i,v in pairs(table) DO
notice how it's still a for loop. 0.o _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> |
|  | | ninga95 Administrator


Posts: 116 Join date: 2010-07-30 Age: 16
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 1:18 pm | |
| To make the for do loop easier to understand you would say For loop makes a command or commands go a set of number of times better example | Code: | L = 10 for i = 1, L do print("Hey") end end |
Last edited by ninga95 on February 9th 2011, 5:07 pm; edited 3 times in total |
|  | | ninga95 Administrator


Posts: 116 Join date: 2010-07-30 Age: 16
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 1:21 pm | |
| Also naknak i and v are just vairable names you can set different variables to it as long as the code is defined correctly.
|
|  | | slayer9365 Administrator


Posts: 233 Join date: 2010-07-31 Age: 17
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 2:39 pm | |
| I think that the pairs loops is really a for loop. |
|  | | naknak Administrator


Posts: 855 Join date: 2010-07-30
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 3:27 pm | |
| I never said anything about i and v not being changeable. Pairs is really a for loop, but it is best to understand them separately. |
|  | | slayer9365 Administrator


Posts: 233 Join date: 2010-07-31 Age: 17
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 5:27 pm | |
| Just thought I would point out some technical stuff. |
|  | | naknak Administrator


Posts: 855 Join date: 2010-07-30
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 6:19 pm | |
| |
|  | | slayer9365 Administrator


Posts: 233 Join date: 2010-07-31 Age: 17
 | Subject: Re: Loops, loops, loops.... February 7th 2011, 7:14 pm | |
| I think that you may want to add that you need a minimum of wait() in the while loops. |
|  | | myrco919 Intermediate Scripter


Posts: 187 Join date: 2011-01-21 Age: 13 Location: Holland
 | Subject: Re: Loops, loops, loops.... March 5th 2011, 2:40 pm | |
| "if v.Name == "cookie" then"
you mean
if v == "cookie" then
|
|  | | naknak Administrator


Posts: 855 Join date: 2010-07-30
 | Subject: Re: Loops, loops, loops.... March 5th 2011, 4:57 pm | |
| |
|  | | blueymaddog Administrator


Posts: 1108 Join date: 2010-12-09 Age: 13
 | Subject: Re: Loops, loops, loops.... November 20th 2011, 2:36 am | |
| | slayer9365 wrote: | | I think that the pairs loops is really a for loop. |
repeating what I said, much? O_o_________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> |
|  | | |
Similar topics |  |
|
| | Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| | Who is online? | In total there are 2 users online :: 0 Registered, 0 Hidden and 2 Guests
None
Most users ever online was 19 on April 5th 2012, 4:06 am
|
| Please tell us what time zone you are in here
Got a really good idea? Post it in projects and it might show up here! |
|