Author |
Message |
TechnoGeek
Joined: Mon Jun 29, 2009 10:34 pm Posts: 51
|
For loop
I am new to Lua but know some C++ and Java and know the standard for loop[ ex. for (x = 0;x < 100;x++)]. What does the for loop in lua do? [for player = 0, self.PlayerCount - 1 do]. Is it even a loop or just a statment?
|
Wed Jul 15, 2009 3:17 pm |
|
|
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
|
Re: For loop
It does the same thing. Ex: Code: for actor in MovableMan.Actors do actor:GibThis(); end Gibs every actor in MovableMan.Actors That is if you have a table of something though. Your syntax is correct for if you are going by variables.
|
Wed Jul 15, 2009 5:11 pm |
|
|
TechnoGeek
Joined: Mon Jun 29, 2009 10:34 pm Posts: 51
|
Re: For loop
Thanks!
|
Wed Jul 15, 2009 5:31 pm |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: For loop
Most of the time, however, in Lua, you won't need loops; an if statement inside an update function is going to run every single time the sim updates, which means that the only time you need a loop is to do more than one thing per frame.
|
Wed Jul 15, 2009 10:18 pm |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
Re: For loop
If you need to do accumlating loops (like in your C++ example) you do: Code: for x = 1, 10, 1 do --blah end for x=1, 10, 1 do end ---> for( x = 1; x <= 10; x+=1) { }
|
Wed Jul 15, 2009 11:38 pm |
|
|
TechnoGeek
Joined: Mon Jun 29, 2009 10:34 pm Posts: 51
|
Re: For loop
Thanks for the visual Kyred. Grif talked abou the update activity repeating itself. What causes the update activity to run, or what has to happen for the code to be executed?
|
Sat Jul 18, 2009 1:10 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: For loop
Anything in the update function of a particle will be executed on every sim update.
|
Sat Jul 18, 2009 1:13 am |
|
|
TechnoGeek
Joined: Mon Jun 29, 2009 10:34 pm Posts: 51
|
Re: For loop
What is a sim update.
|
Sat Jul 18, 2009 2:30 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: For loop
Every time the game's physics engine calculates anything.
Each "step" the game goes through (roughly equal to a frame) the game recalculates the position of everything, collissions, etc.
|
Sat Jul 18, 2009 3:04 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: For loop
If it helps, the sim update is also run through a loop by the program itself. It's basically every time the screen's image changes at all. It's like a frame in an animation.
|
Sat Jul 18, 2009 3:21 am |
|
|
TechnoGeek
Joined: Mon Jun 29, 2009 10:34 pm Posts: 51
|
Re: For loop
Thanks so much!!!!
|
Sat Jul 18, 2009 3:15 pm |
|
|
|