Data Realms Fan Forums http://45.55.195.193/ |
|
Counting Particle-s http://45.55.195.193/viewtopic.php?f=73&t=15732 |
Page 1 of 2 |
Author: | Mind [ Sun Jul 05, 2009 4:04 am ] |
Post subject: | Counting Particle-s |
Can you count particles with lua? Like a variable, such as "ParticleCount" or something. |
Author: | BlackNecro [ Sun Jul 05, 2009 4:09 am ] |
Post subject: | Re: Counting Particle |
What sorta particles do you wanna count? If you just want all do local count = 0 for particle in MovableMan.Particles do count = count + 1 end |
Author: | Mind [ Sun Jul 05, 2009 4:10 am ] |
Post subject: | Re: Counting Particle |
No... that does nothing.... I don't think so at least. That's just increase count by one every Sim update.. |
Author: | BlackNecro [ Sun Jul 05, 2009 4:23 am ] |
Post subject: | Re: Counting Particle |
Mind wrote: No... that does nothing.... I don't think so at least. That's just increase count by one every Sim update.. More like increases count by one on every loop through particles. |
Author: | Mind [ Sun Jul 05, 2009 4:24 am ] |
Post subject: | Re: Counting Particle-s |
But it keeps increasing and never stops... |
Author: | TheValiant [ Sun Jul 05, 2009 4:36 am ] |
Post subject: | Re: Counting Particle-s |
If you declare the variable "count" in the update function, it'll reset the count to 0, then recount all the particles. I don't know much Lua, so I'm taking an educated shot in the dark, but this is my pov: Code: function Create(self) local count; end function Update(self) count = 0; for particle in MovableMan.Particles do count = count + 1; end end |
Author: | CrazyMLC [ Sun Jul 05, 2009 4:56 am ] |
Post subject: | Re: Counting Particle-s |
If count > 50 then count = count -1 |
Author: | mail2345 [ Sun Jul 05, 2009 5:40 am ] |
Post subject: | Re: Counting Particle-s |
Try: Code: function Update(self) count = 0; for particle in MovableMan.Particles do count = count + 1; end for item in MovableMan.Items do count = count + 1; end for actor in MovableMan.Actors do count = count + 1; end end |
Author: | Kyred [ Sun Jul 05, 2009 6:13 am ] |
Post subject: | Re: Counting Particle-s |
Mind wrote: Can you count particles with lua? Like a variable, such as "ParticleCount" or something. You guys are over complicating things . This is the answer you seek: Code: local particleCount = #MovableMan.Particles; MovableMan.Particles is a Lua 'table'. Each element of the table is a particle. To get the number of elements in a Lua table, you use the # operator. http://lua-users.org/wiki/TablesTutorial Try typing this into the console in game and see what I mean: Code: print(#MovableMan.Particles); |
Author: | mail2345 [ Sun Jul 05, 2009 6:19 am ] |
Post subject: | Re: Counting Particle-s |
Knew I forgot something. Revised code: Code: code = #MovableMan.Particles + #MovableMan.Items + #MovableMan.Actors |
Author: | Mind [ Sun Jul 05, 2009 11:16 pm ] |
Post subject: | Re: Counting Particle-s |
Thanks for showing me, but can you only print how many particles there are that pass certain requirements? It'd seem printing that would print the total number of partciles no matter the circumstance. Edit: Kyred, it just gave me an error about trying to find the length of "Particle". |
Author: | Kyred [ Sun Jul 05, 2009 11:53 pm ] |
Post subject: | Re: Counting Particle-s |
Mind wrote: Thanks for showing me, but can you only print how many particles there are that pass certain requirements? It'd seem printing that would print the total number of partciles no matter the circumstance. Edit: Kyred, it just gave me an error about trying to find the length of "Particle". Well I'll be fudge. It really isn't a Lua table. It's a function o_O However, MOPixels and MOSParticles are tables, so it should work for those. If you want to add in circumstance (ie. if statements), then you would have to use a for loop like mail2345 was using. |
Author: | TheLastBanana [ Mon Jul 06, 2009 12:03 am ] |
Post subject: | Re: Counting Particle-s |
MOPixels and MOSParticles seem to only be returning how many scripted entities of that type there are, if I remember correctly. |
Author: | Mind [ Mon Jul 06, 2009 12:10 am ] |
Post subject: | Re: Counting Particle-s |
Like can you do "MovableMan.Particles closer than 50 pixels"? As in find how many are less than 50 pixels away? |
Author: | piipu [ Mon Jul 06, 2009 12:35 am ] |
Post subject: | Re: Counting Particle-s |
Code: function Update(self) self.count = 0 for particle in MovableMan.Particles do if (particle.Pos - self.Pos).Magnitude < 50 then --if distance is < 50 self.count = self.count + 1 end end end |
Page 1 of 2 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |