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



Reply to topic  [ 11 posts ] 
 Duplication Problem 
Author Message
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Duplication Problem
Im having a problem in which Im trying to get a type of toggle going on,

What I want is when an MOPixel is created, the script attached to said MOPixel would check for duplicates of itself on Create and delete it and itself, if not then it stays. Problem is, Instead of finding a duplicate, it finds itself therefore deleting itself.

I tried something like this, but what I just described is happening. No errors either.

Code:
function Create(self)

   for particle in MovableMan.Particles do
      if particle.PresetName == self.PresetName then
         self.particle = particle
         self.particle.ToDelete = true
         self.ToDelete = true
      else
         self.enable = true
         break
      end
   end
end


Any way I can counter this?


Thu May 05, 2011 9:35 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Duplication Problem
And if you add in the if something like if the particle is not self, or something like that?


Thu May 05, 2011 11:35 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Duplication Problem
try:
if ToMOPixel(self.particle) ~= self


Fri May 06, 2011 1:08 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Duplication Problem
I get errors with it.

I can try and make it a MOSParticle and use ToMOSParticle() instead.

EDIT: Or ToMovableObject(). Still errors.


EDIT EDIT: Well I guess it cant check if its the same particle if it doesn't even have the particle yet. Huuuurrrrrrrrrrrrr

EDIT EDIT EDIT: Im still having problems with this, its talking about "no such operator defined".


Fri May 06, 2011 7:10 am
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Duplication Problem
then try getting rid of the ToMOPixel


Fri May 06, 2011 4:40 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Duplication Problem
Still says the exact same thing.

Heres the entire script if it helps.

Code:
function Create(self)
   self.enable = true
   
   for particle in MovableMan.Particles do
      if particle ~= self then
         self.enable = true
      else
         self.particle = ToMOPixel(particle)
         self.particle.ToDelete = true
         self.ToDelete = true
         self.enable = false
         break
      end
   end
   
   for actor in MovableMan.Actors do
      if SceneMan:ShortestDistance(actor.Pos, self.Pos, true).Magnitude < 60 then
         self.parent = actor
         break
      end
   end
end

function Update(self)

   if(MovableMan:IsActor(self.parent)) and self.enable then
      self.ToDelete = false
      self.ToSettle = false
      self.PinStrength = 1000
      self.Age = 1
      self.Pos = self.parent.Pos + Vector(0,-30)
   else
      self.ToDelete = true
   end
end


Fri May 06, 2011 8:23 pm
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: Duplication Problem
if you want only one pixel to exist at the same time, then use global boolean
if you want few of them, with their own parents - use global boolean table
my opinion

edit:
or just a proximity check
if (particle.Pos - self.Pos).Magnitude > 5 then
blah-blah
end


Sat May 07, 2011 12:43 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Duplication Problem
How would I go on about doing this?

I probably know what your talking about, just you put it in a different way.

EDIT: Proximity just checks if any MOPixel would be in range. Im trying to get it to check if its a certain type of pixel.


Sat May 07, 2011 12:57 am
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: Duplication Problem
this pixel is fired from the gun, isn't it?
and you don't want to do anything with the gun?
then use this:
Code:
function Create(self)
    for i = 1, MovableMan:GetMOIDCount() - 1 do
        local mo = MovableMan:GetMOFromID(i)
        if (mo.Pos - self.Pos).Magnitude < 40 and mo.ClassName == "HDFirearm" and mo.PresetName == "your gun name" and mo.Sharpness == 0 then
            self.parent = ToActor(MovableMan:GetMOFromID(mo.RootID))
            self.weapon = ToHDFirearm(mo)
            self.weapon.Sharpness = 1
        else
            self.ToDelete = true
        end
    end
end

function Update(self)
    if(MovableMan:IsActor(self.parent)) then
        self.ToDelete = false
        self.ToSettle = false
        self.PinStrength = 1000
        self.Age = 1
        self.Pos = self.parent.Pos + Vector(0,-30)
    else
        self.ToDelete = true
        self.weapon.Sharpness = 0
    end
end

function Destroy(self)
    if self.weapon and MovableMan:ValidMO(self.weapon) then
        self.weapon.Sharpness = 0
    end
end


this script won't let itself to create 2 or more pixels with one parent
hadn't tested it, btw

edit:
where did you get your script?
if you've written it by yourself, then i've got bad news for you.
at first lines you starting to cycle through all particles on the scene, right?
every particle on the scene, exept this scripted pixel ~= this pixel
you write:
if particle ~= self then
self.enable = true
but
if particle == self then
*delete 'em all*
wth?
the script finds your scripted pixel, this scripted pixel == self, and it deletes the pixel
what were you expecting from it?


Sat May 07, 2011 11:32 am
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: Duplication Problem
Well like I said in the OP, that's what I was having trouble with, it finding itself and deleting itself without the duplicate.

This script you gave me seems to have trouble finding the weapon. I get an error saying that self.weapon is a nil value so that's what I presume. I did put the weapon's name where you told me to and even a print(self.weapon) to make sure that it didn't find it or can't get past that first check properly.

Fooling around with the gun in this script is perfectly fine, all it does is activate something in relative to another script which would check if this particle exists, then continues on with it's script.

From what I can tell with your script, it just deletes itself if another of itself exists. I want it to delete itself and that duplicate, sort of like a toggle function.

Thanks anyhow, I might play around with this script to get it right.

EDIT: I got it, messing around with the weapon's sharpness did the trick (That's why It didn't get the weapon, I didn't give it a sharpness value.) and got it to constantly check if the sharpness is the same, if not then switch it back which in return would tell both particles to delete itself.

Thanks guys.


Sun May 08, 2011 1:15 am
Profile

Joined: Fri Feb 25, 2011 3:52 pm
Posts: 39
Reply with quote
Post Re: Duplication Problem
yep, i've forgotten the most important thing - define sharpness in ini file.
so, it works. good luck.


Sun May 08, 2011 12:19 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.285s | 13 Queries | GZIP : Off ]