View unanswered posts | View active topics It is currently Thu Dec 26, 2024 6:12 pm



Reply to topic  [ 8 posts ] 
 Animating MOSParticles 
Author Message
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Animating MOSParticles
So I'm trying to get all MOSParticles in a list to animate at a fixed rate regardless of the time of origin.

This should work, but isn't; it's giving me errors about comparing nil with number on particle.Frame. Any idea why?

edit well I shouldn't say why but how could I go about fixing it, it's pretty obviously thinking particle is not a good enough pointer

Code:
   for particle in MovableMan.Particles do
      if string.find (table.concat(shotlist),particle.PresetName) then
         if particle.ClassName == "MOSParticle" then
            if particle.Age % 50 == 0 then
               if particle.Frame < 5 then
                  particle.Frame = particle.Frame + 1;
               elseif particle.Frame == 5 then
                  particle.Frame = 0;
               end
            end
         end
      end
   end


Sat Jul 25, 2009 12:26 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Animating MOSParticles
Try casting 'particle' to a MOSprite and see if that works.

In the past, I have had issues like this when using MovableMan.Actors and MovableMan.Particles. My guess is that the pointer in 'for <pointerHere> in MovableMan.Particles do' is not inheriting all the traits from its super classes. Dunno why. Might be a Lua and CC compatibility issue.

But, if that's not the problem, then I don't know what is.


Sat Jul 25, 2009 6:45 am
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Animating MOSParticles
Yea, they are funky.

Unfortunately, I would guess casting conflicts with editing variables, so you will need two pointers if you want to access some things and change variables.


Sat Jul 25, 2009 7:05 am
Profile
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Animating MOSParticles
I did some thinking about this, and I think I have some understanding of what's going on.

Several weeks ago, I learned that MovableMan.Particles is actually a function that returns a table, not a Lua table itself (see image way below). I didn't understand why until now.

My guess is that MovableMan.Particles references a function in CC's game engine, not a function in Lua. I am assuming this because Lua functions use a ':' when called, while functions from programming languages like C/C++ and Java use a '.'. I don't know what language CC's engine is written in, but it'll most likely be some C based language. Unlike Lua, these languages do not support dynamic type.

The pointers returned by MovableMan.Particles are classes of MOPixels, MOSParticles, and AEmitters. However, each of these particle classes have different properties from each other. Pointers returned by MovableMan.Particles can only have properties that are common to these three classes, since the language that MovableMan.Particles is written in does not support dynamic type. (The actual type that's returned is probably either a MovableObject, or some Particle interface).

When these pointers are passed to Lua, it then adds in the properties of that pointer's specific class. However, any traits from super classes in between get lost in translation, since these pointers did not have these values when CC's engine passed the pointers over. So, Lua just fills in the gaps with 'nil's.

Keep in mind, this is only a hunch. I might be wrong on some minor points, but I think it might accurately explain why Movable.Actors, MovableMan.Particles, and such act weird.

Yet, I could also be completely wrong and just blowing confetti out my ass.

Image

@Grif: Yes, you shouldn't of said why :P


Sat Jul 25, 2009 7:45 am
Profile
User avatar

Joined: Mon Jun 30, 2008 9:13 pm
Posts: 499
Location: Finland
Reply with quote
Post Re: Animating MOSParticles
Kyred wrote:
wall-o-text

And therefore, try using ToMOSParticle(particle).Frame.


Sat Jul 25, 2009 11:27 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: Animating MOSParticles
Kyred, that sounds about right - the engine is written in C++ and unless Data specifically made them dynamic classes, it would make sense that it would result in this kind of behavior. I think Piipu is also on the spot about using ToMOSParticle too. Make sure to check that it actually is an MOSParticle first, though.


Sat Jul 25, 2009 8:37 pm
Profile WWW
User avatar

Joined: Sun May 31, 2009 1:04 am
Posts: 308
Reply with quote
Post Re: Animating MOSParticles
I just found some hard proof! I tried setting MovableMan.Particles to nil, and it told me what the function's return type was. It returns a MovableObject.

Image


Mon Jul 27, 2009 8:20 am
Profile
User avatar

Joined: Mon Oct 06, 2008 2:04 am
Posts: 1559
Reply with quote
Post Re: Animating MOSParticles
I've never seen so many Sparkle Mages in one place.

I hope this helps grif, he's been stuck on this one for a few days now.


Tue Jul 28, 2009 12:24 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.659s | 13 Queries | GZIP : Off ]