Data Realms Fan Forums http://45.55.195.193/ |
|
This isn't working!! http://45.55.195.193/viewtopic.php?f=73&t=18892 |
Page 1 of 1 |
Author: | Joe [ Wed Jun 02, 2010 7:32 pm ] |
Post subject: | 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 |
Author: | Areku [ Wed Jun 02, 2010 8:32 pm ] |
Post subject: | 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. |
Author: | Joe [ Wed Jun 02, 2010 9:00 pm ] |
Post subject: | 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. |
Author: | TheLastBanana [ Wed Jun 02, 2010 11:31 pm ] |
Post subject: | 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; |
Author: | Joe [ Thu Jun 03, 2010 1:41 am ] |
Post subject: | 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? |
Author: | Petethegoat [ Thu Jun 03, 2010 1:44 am ] |
Post subject: | 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; |
Author: | Duh102 [ Thu Jun 03, 2010 1:49 am ] |
Post subject: | 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? |
Author: | Joe [ Thu Jun 03, 2010 2:30 am ] |
Post subject: | Re: This isn't working!! |
Are you saying that MOPixels can have Gibs? |
Author: | TheLastBanana [ Thu Jun 03, 2010 2:46 am ] |
Post subject: | 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. |
Author: | Duh102 [ Thu Jun 03, 2010 3:19 am ] |
Post subject: | Re: This isn't working!! |
Joe wrote: MOPixel Oh, that would stop it. Nevermind me then. |
Author: | Joe [ Thu Jun 03, 2010 3:59 am ] |
Post subject: | 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 ![]() |
Author: | TheLastBanana [ Thu Jun 03, 2010 4:08 am ] |
Post subject: | 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. |
Author: | Daman [ Thu Jun 03, 2010 4:09 am ] |
Post subject: | 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 |
Author: | Joe [ Thu Jun 03, 2010 5:06 am ] |
Post subject: | Re: This isn't working!! |
@TLB & Daman: Okay, will do. Thanks guys! |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |