Data Realms Fan Forums http://45.55.195.193/ |
|
Self regenerating MOPixels http://45.55.195.193/viewtopic.php?f=73&t=20031 |
Page 1 of 1 |
Author: | Roast Veg [ Mon Oct 25, 2010 10:55 pm ] |
Post subject: | Self regenerating MOPixels |
In response to the discovery that all children of MovableObject can be scripted, I did some experimentation. I have a script that is supposed to create an MOPixel upon its own Destroy function. Every time the pixel is destroyed, however, the console returns: Quote: ERROR: Tried to add a Particle that already exists in the simulation! So, without further ado, here is the script: Code: function Create(self) self.positionX = nil self.positionY = nil end function Update(self) self.Age = 1 self.RotAngle = 0 self.ToSettle = false self:NotResting(); self.positionX = self.Pos.X self.positionY = self.Pos.Y end function Destroy(self) self.particle = CreateMOPixel("Red Fluid" , "Fluid.rte"); self.particle.Pos = Vector(self.positionX + 1, self.positionY - 1); MovableMan:AddParticle(self.particle); end Any ideas? |
Author: | zalo [ Tue Oct 26, 2010 4:53 am ] |
Post subject: | Re: Self regenerating MOPixels |
Maybe have two different MOPixels that alternate, Red Fluid spawns Red Fluid1 and Red Fluid1 Spawns Red Fluid. Also, they might be a problem trying to get self. vars on destroy, but I don't know. Try Globals just to see if it works. |
Author: | Roast Veg [ Tue Oct 26, 2010 1:44 pm ] |
Post subject: | Re: Self regenerating MOPixels |
I originally used globals for this script, but CaveCricket told me to switch. It changed nothing. I will try some sort of alternation, though. |
Author: | findude [ Tue Oct 26, 2010 2:18 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Localize the variable, move it out of Destroy() to an if self.ToDelete then in Update() |
Author: | Roast Veg [ Tue Oct 26, 2010 2:20 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Ok, will do that too. Anything else before I actually get to work on this thing? |
Author: | findude [ Tue Oct 26, 2010 2:57 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Well, uh, all unitialized variables start as nil, undefined. Why do you need said variables anyways? |
Author: | Roast Veg [ Tue Oct 26, 2010 3:10 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Uh, yea I guess I don't need those now. So now I have two scripts, each creating the other in an if statement on the Update() function. Script 1: Code: function Update(self) self.Age = 1 self.RotAngle = 0 self.ToSettle = false self:NotResting(); self.positionX = self.Pos.X self.positionY = self.Pos.Y if self.ToDelete == true then self.multiple = CreateMOPixel("Red fluid" , "Fluid.rte"); self.multiple.Pos = Vector(self.Pos.X + 1, self.Pos.Y - 1); MovableMan:AddParticle(self.multiple); end end Script 2: Code: function Update(self) self.Age = 1 self.RotAngle = 0 self.ToSettle = false self:NotResting(); self.positionX = self.Pos.X self.positionY = self.Pos.Y if self.ToDelete == true then self.multiple = CreateMOPixel("Red fluid 1" , "Fluid.rte"); self.multiple.Pos = Vector(self.Pos.X + 1, self.Pos.Y - 1); MovableMan:AddParticle(self.multiple); end end HOORAH! It works now! It er... doesn't do what I expected it to do, but at least there are no errors any more. Thanks guys for the help. |
Author: | findude [ Tue Oct 26, 2010 3:44 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Localize. The. Particle. Pointers. Okay? It's saving up the pointer for no reason at all. Doesn't affect anything, but is bad just because. Code: local particle = CreatMOPixel("lrn2localize") particle.Pos = self.Pos MovableMan:AddParticle(particle) And again, why on earth are you storing the position in two seperate variables, especially since you don't even use them at all? |
Author: | Roast Veg [ Tue Oct 26, 2010 3:48 pm ] |
Post subject: | Re: Self regenerating MOPixels |
findude wrote: Okay? Okay, okay, calm down. findude wrote: And again, why on earth are you storing the position in two seperate variables, especially since you don't even use them at all? Uh, yea, should have deleted that bit of the script... my mistake. I'll clean it up some more. |
Author: | findude [ Tue Oct 26, 2010 4:00 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Roast Veg wrote: findude wrote: Okay? Okay, okay, calm down. I mad. But yeah, clean script not only benefits the developement process but also helps anyone looking at it trying to figure out what it does. Keep it clean! |
Author: | Roast Veg [ Tue Oct 26, 2010 4:10 pm ] |
Post subject: | Re: Self regenerating MOPixels |
Scripts are all nice and daisy fresh, but I made the pixels GetHitByMOs = 1. Causes game crashing errors, don't you know. Must remember never to do that again. Anyway, script works, whatever. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |