View unanswered posts | View active topics It is currently Fri Dec 27, 2024 10:05 am



Reply to topic  [ 11 posts ] 
 Self regenerating MOPixels 
Author Message
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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?


Mon Oct 25, 2010 10:55 pm
Profile

Joined: Sat Feb 03, 2007 7:11 pm
Posts: 1496
Reply with quote
Post 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.


Tue Oct 26, 2010 4:53 am
Profile WWW
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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.


Tue Oct 26, 2010 1:44 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Self regenerating MOPixels
Localize the variable, move it out of Destroy() to an if self.ToDelete then in Update()


Tue Oct 26, 2010 2:18 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post Re: Self regenerating MOPixels
Ok, will do that too.

Anything else before I actually get to work on this thing?


Last edited by Roast Veg on Tue Oct 26, 2010 3:01 pm, edited 1 time in total.



Tue Oct 26, 2010 2:20 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post Re: Self regenerating MOPixels
Well, uh, all unitialized variables start as nil, undefined.
Why do you need said variables anyways?


Tue Oct 26, 2010 2:57 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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.


Tue Oct 26, 2010 3:10 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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?


Tue Oct 26, 2010 3:44 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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.


Tue Oct 26, 2010 3:48 pm
Profile
User avatar

Joined: Tue Dec 12, 2006 3:10 pm
Posts: 495
Location: Uncertain quantum state
Reply with quote
Post 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!


Tue Oct 26, 2010 4:00 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Tue May 25, 2010 8:27 pm
Posts: 4521
Location: Constant motion
Reply with quote
Post 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. :oops:

Anyway, script works, whatever.


Tue Oct 26, 2010 4:10 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.038s | 15 Queries | GZIP : Off ]