A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog 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 in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 8th 2016, 10:14 am by naknak

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
July 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 13th 2015, 4:54 pm by naknak

» Who's active?!
April 13th 2015, 4:52 pm by naknak

» Where to go from here.
April 13th 2015, 4:51 pm by naknak

» Genesis Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 10th 2014, 11:43 am by naknak

» local scripts?
July 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
July 10th 2014, 11:36 am by naknak

» Hi. I am new here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
January 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
November 26th 2013, 3:33 pm by Keanu73

» Improve Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Loops, loops, loops....

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

Posts : 878
Join date : 2010-07-30

PostSubject: Loops, loops, loops....   January 21st 2011, 9: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, 8:58 pm; edited 1 time in total
Back to top Go down
raboy117
Novice Scripter
Novice Scripter
avatar

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

PostSubject: Re: Loops, loops, loops....   January 21st 2011, 9: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")'


Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Loops, loops, loops....   January 26th 2011, 9: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
avatar

Posts : 122
Join date : 2010-07-30
Age : 21

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 5: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, 9:07 pm; edited 3 times in total
Back to top Go down
ninga95
Administrator
Administrator
avatar

Posts : 122
Join date : 2010-07-30
Age : 21

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 5: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
Expert Scripter
Expert Scripter
avatar

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

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

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

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 7: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
Expert Scripter
Expert Scripter
avatar

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

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

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

Posts : 878
Join date : 2010-07-30

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

Fair enough.
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
avatar

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

PostSubject: Re: Loops, loops, loops....   February 7th 2011, 11: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
avatar

Posts : 190
Join date : 2011-01-21
Age : 19
Location : Holland

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

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

you mean

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

Posts : 878
Join date : 2010-07-30

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

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

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Loops, loops, loops....   November 20th 2011, 6: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
Sponsored content




PostSubject: Re: Loops, loops, loops....   

Back to top Go down
 
Loops, loops, loops....
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Ω Verax's Programming Tutorials Ω

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