A Roblox Community
You must log in to view most of the sites content. If you do not already have an account click Register below...

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomePortalFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log on automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
slayer9365
 
myrco919
 
m27frogy
 
ninga95
 
CloneTrooper787
 
raboy117
 
trappingnoobs
 
Top posting users this month
m27frogy
 
myrco919
 
blueymaddog
 
ninga95
 
naknak
 
Latest topics
» Keylogging/getting the mouse unnoticed
May 16th 2012, 8:43 pm by naknak

» Nederlands
May 16th 2012, 11:52 am by m27frogy

» みなさん、こんにちは!
May 16th 2012, 10:32 am by myrco919

» Try out the panel!
May 16th 2012, 10:30 am by myrco919

» The Local Script: A Robloxian's Worst Nightmare
May 16th 2012, 10:26 am by myrco919

» You're lost.
May 14th 2012, 4:36 am by m27frogy

» Good news, well sorta!
May 9th 2012, 8:29 pm by ninga95

» AIR, Artificial Intelligence Revised
May 5th 2012, 6:35 am by m27frogy

» local script help:
April 7th 2012, 8:22 am by Lukasm

» How to loop regen creations.
April 7th 2012, 6:34 am by MrNicNac

» Refering to functions as objects?
March 28th 2012, 8:29 am by Sethalonian

» Help new people find their way around the website
March 22nd 2012, 11:43 pm by blueymaddog

» I wanna see if anyone can
March 19th 2012, 1:46 am by blueymaddog

» Dispute Rules
March 14th 2012, 1:22 am by blueymaddog

» Explaining the Basics of a Script with Example
March 11th 2012, 6:37 pm by blueymaddog

» Java or C?
March 10th 2012, 8:48 pm by blueymaddog

» Talk about your favourite hobbies!
March 10th 2012, 8:45 pm by blueymaddog

» Metatables Tutorial
March 10th 2012, 8:43 pm by blueymaddog

» Rules of this forum. Please read!
March 9th 2012, 1:35 pm by blueymaddog

» Epic Ice King Staff
March 9th 2012, 1:34 pm by blueymaddog


Share | 
 

 Loops, loops, loops....

View previous topic View next topic Go down 
AuthorMessage
naknak
Administrator
Administrator


Posts: 855
Join date: 2010-07-30

PostSubject: 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
Back to top Go down
raboy117
Moderator
Moderator


Posts: 75
Join date: 2011-01-19
Age: 14
Location: Canada, PEI, Charlottetown

PostSubject: 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.
Back to top Go down
blueymaddog
Administrator
Administrator


Posts: 1108
Join date: 2010-12-09
Age: 13

PostSubject: 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?>
Back to top Go down
ninga95
Administrator
Administrator


Posts: 116
Join date: 2010-07-30
Age: 16

PostSubject: 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
Back to top Go down
ninga95
Administrator
Administrator


Posts: 116
Join date: 2010-07-30
Age: 16

PostSubject: 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.

Back to top Go down
slayer9365
Administrator
Administrator


Posts: 233
Join date: 2010-07-31
Age: 17

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 2:39 pm

I think that the pairs loops is really a for loop.
Back to top Go down
naknak
Administrator
Administrator


Posts: 855
Join date: 2010-07-30

PostSubject: 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.
Back to top Go down
slayer9365
Administrator
Administrator


Posts: 233
Join date: 2010-07-31
Age: 17

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 5:27 pm

Just thought I would point out some technical stuff.
Back to top Go down
naknak
Administrator
Administrator


Posts: 855
Join date: 2010-07-30

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 6:19 pm

Fair enough.
Back to top Go down
slayer9365
Administrator
Administrator


Posts: 233
Join date: 2010-07-31
Age: 17

PostSubject: 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.
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter


Posts: 187
Join date: 2011-01-21
Age: 13
Location: Holland

PostSubject: Re: Loops, loops, loops....   March 5th 2011, 2:40 pm

"if v.Name == "cookie" then"

you mean

if v == "cookie" then
Back to top Go down
naknak
Administrator
Administrator


Posts: 855
Join date: 2010-07-30

PostSubject: Re: Loops, loops, loops....   March 5th 2011, 4:57 pm

Whoops. Yes.
Back to top Go down
blueymaddog
Administrator
Administrator


Posts: 1108
Join date: 2010-12-09
Age: 13

PostSubject: 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?>
Back to top Go down
 

Loops, loops, loops....

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Lua Loops
» How to hook up an MPK25 with fruity loops?
» Johnny Loops
» Belt Tan
» My first pop song in FL Studio :D

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Scripting Tutorials :: Beginner-