View unanswered posts | View active topics It is currently Sat Apr 27, 2024 6:05 am



Reply to topic  [ 11 posts ] 
 For loop 
Author Message
User avatar

Joined: Mon Jun 29, 2009 10:34 pm
Posts: 51
Reply with quote
Post 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
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Jun 29, 2009 10:34 pm
Posts: 51
Reply with quote
Post Re: For loop
Thanks! :grin:


Wed Jul 15, 2009 5:31 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Jun 29, 2009 10:34 pm
Posts: 51
Reply with quote
Post 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
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Jun 29, 2009 10:34 pm
Posts: 51
Reply with quote
Post Re: For loop
What is a sim update.


Sat Jul 18, 2009 2:30 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Mon Jun 29, 2009 10:34 pm
Posts: 51
Reply with quote
Post Re: For loop
Thanks so much!!!! :grin:


Sat Jul 18, 2009 3:15 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.186s | 15 Queries | GZIP : Off ]