Thane_1Join Date: 2009-04-08 Post Count: 3406 |
I found this line of code online regarding Perlin Noise, and I've never used C, but I was able to convert it a little.
--Before:
for (int y = 0; y < height; y++) {
}
--After:
for (y = 0, y < height, y++) do
end
--I'm guessing the 'y < height' is an if statement, and 'y++' is the increment?
Can someone help? I might just have to use a repeat loop.
~Who's awesome? You're awesome! |
|
|
for y = 0, height, 1 do
-- code
end
0 is the starting point, height is the maximum value, and 1 is the increment
http://wiki.roblox.com/?title=Loops
|
|
|
in lua u start with 1 instead of 0
also tables start at index 1 not 0
3rd argument is the increment (can be decimal)
for i = 1, height, 1 do
print(i)
end
Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444 |
|
|
it's also worth noting that the increment is set to 1 by default so it's redundant in that example
|
|
|
"in lua u start with 1 instead of 0"
what are you talking about? we're using loops here, not arrays
|
|
|
in java/c/c++ u start at 0 like this
for(int i = 0, i < endValue, i++)
{
}
Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444 |
|
|
okay...?
what's different in lua?
|
|
Thane_1Join Date: 2009-04-08 Post Count: 3406 |
Thanks, I didn't realize it was so simple.
~Who's awesome? You're awesome! |
|
|
|
i'm not the idiot here, for some reason you seem to think that for loops in lua need to have a starting value of 1
you don't belong here to help if you don't even know what you're talking about
|
|
|
they normally start at 1 if you dont need to use i
Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444 |
|
Thane_1Join Date: 2009-04-08 Post Count: 3406 |
lol, no need to insult people. Also, it has to start at 0, and I just tested in studio, and a for loop can start from 0.
~Who's awesome? You're awesome! |
|
|
they can start at whatever but if you just wanna loop for a fixed amount of times you dont need to set i to anything other than 1
Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444 |
|
|
if you wanna loop for 10 times u do this
for i = 1, 10 do
end
because this loops for 11 times
for i = 0, 10 do
end
Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444 |
|
|
"in lua u start with 1 instead of 0"
do you not remember saying that?
for loops don't have a specific starting value
|
|
|
yes, i'm aware of that, but that's not what you said at first
|
|
|
for x = -100, 0, 1 do print("Loops can start at ### ######### end |
|