View unanswered posts | View active topics It is currently Sat Dec 28, 2024 3:52 pm



Reply to topic  [ 14 posts ] 
 This isn't working!! 
Author Message
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post This isn't working!!
I'm modding the WH40K Bolter. I need the particle to destroy itself and spawn an explosion, but when I reference the explosion, I get a console error saying that I'm "attempting to reference global 'Destroy' (a nil value)". What do I do?

Here's the code:

Code:
function Update(self)
   local speedMax = 150;
   local speedScalar = 1.0625;
   local Altitude = SceneMan:FindAltitude(self.Pos,100,2)
   
   if self.Vel.Magnitude > speedMax then
      self.Vel= self.Vel;
   else
      self.Vel.X = (self.Vel.X + math.cos(math.sqrt(self.Vel.Y^2 + self.Vel.X^2))) * speedScalar;
      self.Vel.Y = (self.Vel.Y + math.sin(math.sqrt(self.Vel.Y^2 + self.Vel.X^2))) * speedScalar;
   end
   
   if Altitude < 2 then
      Destroy(self);
   end   
end

function Destroy(self)
   local dust = CreateMOSRotating("Bolt Explosion");
   dust.Pos = self.Pos;
   dust.Vel = self.Vel;
   MovableMan:AddMO(dust);
   dust.GibThis(dust);
end


Wed Jun 02, 2010 7:32 pm
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: This isn't working!!
Well, there are a few problems with your script. First of all, GibThis is a function, not a variable, so it should be written dust:GibThis(dust). Then you are asking the code to refer to a function (Destroy) that hasn't yet been defined. Put the "function Destroy (self)" section before the Update(self), and it should work. I guess.


Wed Jun 02, 2010 8:32 pm
Profile WWW
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: This isn't working!!
Thank you for pointing that out, will try...

EDIT: No joy. Still gives me that error. Also, your suggestion about the GibThis function didn't work. It was operational the way it was.


Wed Jun 02, 2010 9:00 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: This isn't working!!
The issue is that you shouldn't be using the Destroy function itself.
If you want something to delete itself, use this:
Code:
self.ToDelete = true;


Wed Jun 02, 2010 11:31 pm
Profile WWW
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: This isn't working!!
Okay, but what if I need something that specifically says "Generate an explosive blast when you hit the ground OR when you hit an actor. The perk of the Destroy function is that it will always run when the particle hits an actor, therefore being deleted. How do I get around that to where that function will run when a certain condition is met?


Thu Jun 03, 2010 1:41 am
Profile
User avatar

Joined: Mon Jun 15, 2009 4:02 pm
Posts: 905
Reply with quote
Post Re: This isn't working!!
Code:
   if Altitude < 2 then
      Destroy(self);
   end   

This is the issue.
Not this:
Code:
function Destroy(self)
   local dust = CreateMOSRotating("Bolt Explosion");
   dust.Pos = self.Pos;
   dust.Vel = self.Vel;
   MovableMan:AddMO(dust);
   dust.GibThis(dust);
end

Just change the Destroy(self); in the first one to self.ToDelete = true;


Thu Jun 03, 2010 1:44 am
Profile WWW
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: This isn't working!!
Joe wrote:
Okay, but what if I need something that specifically says "Generate an explosive blast when you hit the ground OR when you hit an actor.

Why can't you just make the particle have the gibs the explosion particle has, thus when it gibs it will create your explosion? And besides actors and the ground, what else is there for it to not explode against?


Thu Jun 03, 2010 1:49 am
Profile
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: This isn't working!!
Are you saying that MOPixels can have Gibs?


Thu Jun 03, 2010 2:30 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: This isn't working!!
Instead of putting it in a separate function, just copy the destroy code to where you need it.
Also, dust:GibThis() shouldn't have that second dust in there.


Thu Jun 03, 2010 2:46 am
Profile WWW
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post Re: This isn't working!!
Joe wrote:
MOPixel

Oh, that would stop it. Nevermind me then.


Thu Jun 03, 2010 3:19 am
Profile
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: This isn't working!!
TheLastBanana wrote:
Instead of putting it in a separate function, just copy the destroy code to where you need it.


But I need it to execute ONLY when the particle is removed (when it hits an actor) or when it hits the ground. Moving the code from the destroy function to somewhere else means that the particle does nothing when it is destroyed. I think I may have just figured out a way to do this with a variable, but I'll let this thread continue for now.

TheLastBanana wrote:
Also, dust:GibThis() shouldn't have that second dust in there.


The console gives me a syntax error when I don't.

Joe wrote:
Are you saying that MOPixels can have Gibs?

Duh102 wrote:
Joe wrote:
MOPixel

Oh, that would stop it. Nevermind me then.


Ah, I was beginning to get my hopes up :-( . No problem, that's what the code I'm working on is designed to circumvent.


Thu Jun 03, 2010 3:59 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: This isn't working!!
Joe, the Destroy function gets called when the object is deleted or destroyed in any way, no matter what. ToDelete should work just fine, if that's what you want.
As well, you probably have tried dust.GibThis(dust) and dust:GibThis(dust) but neither of those are the way you should do it/will give you a syntax error. If you want to do it the proper way, dust:GibThis() is what you want, with nothing in the brackets.


Thu Jun 03, 2010 4:08 am
Profile WWW
User avatar

Joined: Fri Jan 26, 2007 3:22 am
Posts: 1451
Reply with quote
Post Re: This isn't working!!
Joe wrote:
The console gives me a syntax error when I don't.


good, because you're calling it wrong

you're using a . rather than a :

you should probably read a guide on how functions in metatables work but I know that won't help you because you don't understand metatables

http://lua-users.org/wiki/LuaClassesWithMetatable

check the difference between function usage and variable usage here

GibThis() is a function belonging to the actor metatable, and you call it by passing an actor object through actor:GibThis()

actor in this situation is dust

the correct call would be dust:GibThis()

you've got to understand that you don't need to provide an argument because you're doing so by the portion to the left of the :

tlb is ruining my cred i clearly started typing this post b4 his ehehhhheh


Thu Jun 03, 2010 4:09 am
Profile
User avatar

Joined: Tue Jul 21, 2009 4:36 am
Posts: 347
Location: The place where asses go to be bad
Reply with quote
Post Re: This isn't working!!
@TLB & Daman: Okay, will do. Thanks guys!


Thu Jun 03, 2010 5:06 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 14 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.039s | 15 Queries | GZIP : Off ]