Data Realms Fan Forums
http://45.55.195.193/

For loop
http://45.55.195.193/viewtopic.php?f=73&t=15878
Page 1 of 1

Author:  TechnoGeek [ Wed Jul 15, 2009 3:17 pm ]
Post subject:  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?

Author:  Duh102 [ Wed Jul 15, 2009 5:11 pm ]
Post subject:  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.

Author:  TechnoGeek [ Wed Jul 15, 2009 5:31 pm ]
Post subject:  Re: For loop

Thanks! :grin:

Author:  Grif [ Wed Jul 15, 2009 10:18 pm ]
Post subject:  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.

Author:  Kyred [ Wed Jul 15, 2009 11:38 pm ]
Post subject:  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) { }

Author:  TechnoGeek [ Sat Jul 18, 2009 1:10 am ]
Post subject:  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?

Author:  Grif [ Sat Jul 18, 2009 1:13 am ]
Post subject:  Re: For loop

Anything in the update function of a particle will be executed on every sim update.

Author:  TechnoGeek [ Sat Jul 18, 2009 2:30 am ]
Post subject:  Re: For loop

What is a sim update.

Author:  Grif [ Sat Jul 18, 2009 3:04 am ]
Post subject:  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.

Author:  TheLastBanana [ Sat Jul 18, 2009 3:21 am ]
Post subject:  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.

Author:  TechnoGeek [ Sat Jul 18, 2009 3:15 pm ]
Post subject:  Re: For loop

Thanks so much!!!! :grin:

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/