Author |
Message |
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Counting Particle-s
Can you count particles with lua? Like a variable, such as "ParticleCount" or something.
Last edited by Mind on Sun Jul 05, 2009 4:20 am, edited 1 time in total.
|
Sun Jul 05, 2009 4:04 am |
|
|
BlackNecro
Joined: Sat Dec 02, 2006 12:41 am Posts: 27 Location: Germany
|
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
|
Sun Jul 05, 2009 4:09 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Counting Particle
No... that does nothing.... I don't think so at least. That's just increase count by one every Sim update..
|
Sun Jul 05, 2009 4:10 am |
|
|
BlackNecro
Joined: Sat Dec 02, 2006 12:41 am Posts: 27 Location: Germany
|
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.
|
Sun Jul 05, 2009 4:23 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
Re: Counting Particle-s
But it keeps increasing and never stops...
|
Sun Jul 05, 2009 4:24 am |
|
|
TheValiant
Joined: Mon Jun 08, 2009 10:54 pm Posts: 33
|
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
|
Sun Jul 05, 2009 4:36 am |
|
|
CrazyMLC
Joined: Fri Dec 22, 2006 4:20 am Posts: 4772 Location: Good news everyone!
|
Re: Counting Particle-s
If count > 50 then count = count -1
|
Sun Jul 05, 2009 4:56 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
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
|
Sun Jul 05, 2009 5:40 am |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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/TablesTutorialTry typing this into the console in game and see what I mean: Code: print(#MovableMan.Particles);
|
Sun Jul 05, 2009 6:13 am |
|
|
mail2345
Joined: Tue Nov 06, 2007 6:58 am Posts: 2054
|
Re: Counting Particle-s
Knew I forgot something. Revised code: Code: code = #MovableMan.Particles + #MovableMan.Items + #MovableMan.Actors
|
Sun Jul 05, 2009 6:19 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
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".
|
Sun Jul 05, 2009 11:16 pm |
|
|
Kyred
Joined: Sun May 31, 2009 1:04 am Posts: 308
|
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.
|
Sun Jul 05, 2009 11:53 pm |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Mon Jul 06, 2009 12:03 am |
|
|
Mind
Joined: Thu Mar 06, 2008 10:54 pm Posts: 1360 Location: USA
|
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?
|
Mon Jul 06, 2009 12:10 am |
|
|
piipu
Joined: Mon Jun 30, 2008 9:13 pm Posts: 499 Location: Finland
|
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
|
Mon Jul 06, 2009 12:35 am |
|
|
|