View unanswered posts | View active topics It is currently Sat Apr 27, 2024 12:33 pm



Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
 Counting Particle-s 
Author Message
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post 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
Profile

Joined: Sat Dec 02, 2006 12:41 am
Posts: 27
Location: Germany
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post 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
Profile

Joined: Sat Dec 02, 2006 12:41 am
Posts: 27
Location: Germany
Reply with quote
Post 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
Profile WWW
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post Re: Counting Particle-s
But it keeps increasing and never stops...


Sun Jul 05, 2009 4:24 am
Profile

Joined: Mon Jun 08, 2009 10:54 pm
Posts: 33
Reply with quote
Post 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
Profile
User avatar

Joined: Fri Dec 22, 2006 4:20 am
Posts: 4772
Location: Good news everyone!
Reply with quote
Post Re: Counting Particle-s
If count > 50 then
count = count -1


Sun Jul 05, 2009 4:56 am
Profile WWW
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post 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 :P. 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);


Sun Jul 05, 2009 6:13 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post 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
Profile
User avatar

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

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1359
Location: USA
Reply with quote
Post 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
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post 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
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 18 posts ]  Go to page 1, 2  Next

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.113s | 15 Queries | GZIP : Off ]