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 loops?

Previous Thread :: Next Thread 
RBXSummerDay is not online. RBXSummerDay
Joined: 07 Oct 2010
Total Posts: 99
26 Sep 2012 01:46 PM
hey guys. i need some help with for loops. i dont quite understand them yet

for 1, 10 do
print("lol")
end

i get this error

input:1: [name] expected near '1'

what is wrong? pls help


the [ is < and ] is >
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
26 Sep 2012 01:53 PM
When you use a for loop, you need to supply a variable.
Example:

for i = 1, 10 do
print(i)
end


Output >
1
2
3
4
5
6
7
8
9
10


The variable can be whatever you want; it doesn't just have to be i.
Report Abuse
RBXSummerDay is not online. RBXSummerDay
Joined: 07 Oct 2010
Total Posts: 99
26 Sep 2012 01:55 PM
for variable = 1, 10 do
print(i)
end


why does it keep printing nil? im so confused
Report Abuse
RBXSummerDay is not online. RBXSummerDay
Joined: 07 Oct 2010
Total Posts: 99
26 Sep 2012 01:58 PM
please help me :(
Report Abuse
XxChopSlaperxX is not online. XxChopSlaperxX
Joined: 09 Nov 2010
Total Posts: 3112
26 Sep 2012 02:05 PM
you do

print(variable)

in your case
Report Abuse
RBXSummerDay is not online. RBXSummerDay
Joined: 07 Oct 2010
Total Posts: 99
26 Sep 2012 02:09 PM
ah i see. is there any way to count backwards?
Report Abuse
Daelus is not online. Daelus
Joined: 06 Sep 2012
Total Posts: 144
26 Sep 2012 02:09 PM
--[[
Supply variable is defined as "i".
You call "i" on the second line, printing the number.
]]

for i = 1, 10 do
print(i)
end



--[[
Supply variable is defined as "variable".
You call undefined "i" on the second line, printing nil.
]]

for variable = 1, 10 do
print(i)
end
Report Abuse
usama8800 is not online. usama8800
Joined: 29 Dec 2009
Total Posts: 225
26 Sep 2012 02:12 PM
the optional iterator is what u need
for i = 10 , 1 , -1 do -- makes i 10 and adds -1 on it until it becomes 1
print(i)
end
Report Abuse
Daelus is not online. Daelus
Joined: 06 Sep 2012
Total Posts: 144
26 Sep 2012 02:14 PM
That wouldn't work, usama.
for loops are meant to count up, and it will stop once the supply variable is at, or higher, than the max value.
Report Abuse
RBXSummerDay is not online. RBXSummerDay
Joined: 07 Oct 2010
Total Posts: 99
26 Sep 2012 02:15 PM
for i = 10, 1, -2 do
print(i)
end

prints out 10 8 6 4 2 subtracting 2 each time. i think i get it now
thanks

new question tho. what is pairs? i see it a lot in other scripts
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
26 Sep 2012 02:16 PM
"for loops are meant to count up, and it will stop once the supply variable is at, or higher, than the max value."


Wrong. For loops can count both up and down, depending on the third argument.
Report Abuse
Daelus is not online. Daelus
Joined: 06 Sep 2012
Total Posts: 144
26 Sep 2012 02:19 PM
That's interesting. I guess I've always made the script wrong; it's never worked for me.
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