Top posting users this month | |
Latest topics | » Where to go from here.September 14th 2020, 1:20 pm by MrNicNac» Send me an EmailSeptember 14th 2020, 1:16 pm by MrNicNac» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]July 6th 2015, 7:38 pm by m27frogy» New Site PossiblyJuly 6th 2015, 4:16 pm by m27frogy» Ambassador!April 15th 2015, 11:40 pm by naknak» Boop - TagApril 13th 2015, 9:46 pm by naknak» Vip Class ScriptApril 13th 2015, 4:54 pm by naknak» Who's active?!April 13th 2015, 4:52 pm by naknak» Genesis PointJuly 17th 2014, 7:04 pm by branefreez» Reward SystemJuly 17th 2014, 5:41 am by m27frogy» Script RequestJuly 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 hereApril 26th 2014, 4:01 pm by altshiftkey» What's your favorite sport?January 1st 2014, 2:13 pm by m27frogy» FlashLight ScriptJanuary 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 CodingOctober 26th 2013, 1:12 pm by pook03» Simple ButtonSeptember 1st 2013, 6:19 pm by branefreez |
|
| Loops, loops, loops.... | |
| | Author | Message |
---|
naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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 | |
| | | raboy117 Novice Scripter
Posts : 75 Join date : 2011-01-19 Age : 27 Location : Canada, PEI, Charlottetown
| Subject: 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")'
| |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: 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 | |
| | | ninga95 Administrator
Posts : 122 Join date : 2010-07-30 Age : 29
| Subject: 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 | |
| | | ninga95 Administrator
Posts : 122 Join date : 2010-07-30 Age : 29
| Subject: 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.
| |
| | | slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Loops, loops, loops.... February 7th 2011, 6:39 pm | |
| I think that the pairs loops is really a for loop. | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: 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. | |
| | | slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: Re: Loops, loops, loops.... February 7th 2011, 9:27 pm | |
| Just thought I would point out some technical stuff. | |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Loops, loops, loops.... February 7th 2011, 10:19 pm | |
| | |
| | | slayer9365 Expert Scripter
Posts : 233 Join date : 2010-07-31 Age : 29
| Subject: 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. | |
| | | myrco919 Intermediate Scripter
Posts : 190 Join date : 2011-01-21 Age : 26 Location : Holland
| Subject: Re: Loops, loops, loops.... March 5th 2011, 6:40 pm | |
| "if v.Name == "cookie" then"
you mean
if v == "cookie" then
| |
| | | naknak Administrator
Posts : 878 Join date : 2010-07-30
| Subject: Re: Loops, loops, loops.... March 5th 2011, 8:57 pm | |
| | |
| | | blueymaddog Administrator
Posts : 1081 Join date : 2010-12-09 Age : 26
| Subject: 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 | |
| | | Sponsored content
| Subject: Re: Loops, loops, loops.... | |
| |
| | | | Loops, loops, loops.... | |
|
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 136 on October 21st 2024, 12:16 pm
|
| 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! |
|