generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: For i =

Previous Thread :: Next Thread 
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 04:49 PM
may some one please tell me what this means?

for i = 1,20 do
BLAH BLAH BLAH
end
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 04:51 PM
for i = 1,20 do -- run loop 20 times adding 1 to value( i ) each time.
blahblahblah -- the code you want to run in the code it could be,
print(i) -- show loop iteration (value of i)
end -- ends looping code,
Report Abuse
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 04:53 PM
but whats the point of adding 1 to i then?
Report Abuse
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
27 Nov 2013 04:54 PM
.-. to repeat the loop
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 04:56 PM
for codes like

for i = 1,0,-0.1 do -- go from 1 to 0 at 0.1 per loop
brick.Transparency = i -- change to value of i
wait(0.1)
end

this would give a smooth transparency change instead of this.

brick.Transparency = 1
wait(0.1)
brick.Transparency = 0.9
wait(0.1)
etc...
brick.Transparency = 0
Report Abuse
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 04:56 PM
so if i did i = 2,20
does that mean it will run the script 40 times?
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 04:58 PM
for i = s,e,i do

s = start number
e = end number
i = interval

total loops can be worked out as ((e-s)/i)
Report Abuse
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 05:00 PM
mind telling me in math terms?, Like S*S/I ???
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 05:00 PM
((e-s+1)/i) sorry,

so if

s = 1
e = 10
i = 0.1

then

10 - 1 + 1 = 10
10/0.1 = 100

so the loop will run 100 times
Report Abuse
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 05:02 PM
But do i need to add a i interval in the equation?
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 05:05 PM
if you dont then it will default as 1

-----------------------
for i = 1,10 do

is the same as

for i = 1,10,1 do
Report Abuse
djboy is not online. djboy
Joined: 16 Mar 2008
Total Posts: 794
27 Nov 2013 05:06 PM
ok, Thanks :D
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
27 Nov 2013 05:07 PM
No.



for VAR = START, STOP, STEP do
-- CODE
end


This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if START was lower) or greater than STOP (if START was higher). At the end of the loop, VAR is incremented by STEP, which has a default value of 1.

Sound confusing? Let's look at some examples.


for i = 1, 20 do
print(i)
end
-- this prints numbers 1 to 20, increasing by 1 each time

for i = 10, 0, -1 do
print(i)
end
-- this prints numbers 10 to 0, increasing by -1 each time

for i = 23, 24, 2 do
print(i)
end
-- this prints number 23



Here's a basic look at that the for loop is like:


FOR(VAR, START, STOP, STEP, CODE)
    if STEP is not a number
        STEP = 1
    end if
    if STEP < 0
        while START < STOP
            execute CODE
            START = START + STEP
        end while
    elseif STEP > 0
        while START > STOP
            execute CODE
            START = START + STEP
        end while
    end if
end FOR


You'll notice the for loop is considered a PRE-TEST loop. This means the condition (START > STOP or START < STOP) is checked BEFORE the code is executed. You may also notice the code will not be executed if your STEP is 0.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
27 Nov 2013 05:09 PM
"This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if START was lower) or greater than STOP (if START was higher). At the end of the loop, VAR is incremented by STEP, which has a default value of 1."


Correction:

This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if STEP was negative) or greater than STOP (if STEP was positive). At the end of the loop, VAR is incremented by STEP, which has a default value of 1.
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 05:12 PM
all you did was add the fact that if endnumber is less that startnumber then step is default negative 1.

what i said was by no means wrong,
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
27 Nov 2013 05:13 PM
"what i said was by no means wrong,"

That No wasn't to your post. XD
I lateposted because I decided to write a novel about the for loop. It was a response to this post:

"so if i did i = 2,20
does that mean it will run the script 40 times?"



Apologies. Shoulda known you guys would have been posting while I spent my two hours writing that novel. XD
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 05:14 PM
ahh, it happens,

although, others would say you got ninja'd ;)
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
27 Nov 2013 05:19 PM
I'll admit I'm not as fast as I once was ....
Does that make me old? D:
Report Abuse
PRESTIGIOUSaLEGEND is not online. PRESTIGIOUSaLEGEND
Joined: 16 Apr 2011
Total Posts: 1765
27 Nov 2013 05:21 PM
"with age comes wisdom"
Report Abuse
2DB is not online. 2DB
Joined: 18 Nov 2013
Total Posts: 109
27 Nov 2013 05:23 PM
"and age"
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
27 Nov 2013 05:43 PM
"and no teeth"
Report Abuse
kevincatssing is online. kevincatssing
Joined: 29 Aug 2011
Total Posts: 15763
27 Nov 2013 05:47 PM
"and no hair"
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image