Data Realms Fan Forums
http://45.55.195.193/

Object Spawning Script not working
http://45.55.195.193/viewtopic.php?f=73&t=16279
Page 1 of 1

Author:  CaveCricket48 [ Wed Aug 19, 2009 10:55 pm ]
Post subject:  Object Spawning Script not working

I have a script that is attached to a MOSRotating and is supposed to:

In funtion Create(self)
1. Find the closest actor within 50 pixels.
2. Make the found actor the "target"
2B. If no actor found, gib itself.

In function Update(self)
1. If the "target" presses crouch, create the specified MOSR.
2. Position the MOSR where the actor is.
3. Keep self from settling/deleting/going away.

Errors I have include that when the main MOSR with the script is created, it deletes itself. Another problem is that when I take away the else self:GibThis(); I get an error about "trying to index field "target" a nil value". Help please.

Code:
function Create(self)
   self.target = nil;

   local curdist = 50;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
      if dist.Magnitude < curdist then
      self.target = actor;
      break;
   else
      self:GibThis();
      end
   end
end

function Update(self)
   if self.target:GetController():IsState(Controller.BODY_CROUCH) then
      local shield = CreateMOSRotating("Shield Generator Graft Shield");
      shield.Pos = self.target.Pos;
      MovableMan:AddParticle(shield);
      self.Pos = self.target.Pos;
      self:NotResting();
      self.Age = 0;
      self.ToSettle = false;
      self.ToDelete = false;
      end
end

Author:  Mind [ Wed Aug 19, 2009 11:07 pm ]
Post subject:  Re: Object Spawning Script not working

Code:
function Create(self)
   self.target = nil;

   local curdist = 50;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
      if dist.Magnitude < curdist then
            self.target = actor;
            break;
      else
            self:GibThis();
      end
   end
end

function Update(self)
   if self.target:GetController():IsState(Controller.BODY_CROUCH) then
      local shield = CreateMOSRotating("Shield Generator Graft Shield");
      shield.Pos = self.target.Pos;
      MovableMan:AddParticle(shield);
      self.Pos = self.target.Pos;
      self:NotResting();
      self.Age = 0;
      self.ToSettle = false;
      self.ToDelete = false;
   end
end


Dunno if this will work, but the tabbing was a little messed up :)

Also, I also do not know if this would be the way to do it, but I might, instead of ur update method do something like

Code:
if self.target == nil then
     self:GibThis
else
    [whatever you had]
end


Again, I'm not 100% or anything this is right, but yeah...

Author:  Grif [ Wed Aug 19, 2009 11:19 pm ]
Post subject:  Re: Object Spawning Script not working

http://pastebin.com/m541777af

Author:  Duh102 [ Wed Aug 19, 2009 11:19 pm ]
Post subject:  Re: Object Spawning Script not working

Mind wrote:
Dunno if this will work, but the tabbing was a little messed up :)

Tabbing doesn't matter in Lua (though it makes everything SO much more easy to read).

Author:  CaveCricket48 [ Wed Aug 19, 2009 11:30 pm ]
Post subject:  Re: Object Spawning Script not working

Grif: The script doesn't seem to do anything at all. The main MOSRotating with the script isn't visible, either.

Author:  Mind [ Wed Aug 19, 2009 11:33 pm ]
Post subject:  Re: Object Spawning Script not working

It could also be if you forgot something in the ini, which is doubtful, but lua doesn't work on held devices or aemitters emitted out of aemitter either ( I think). Not that those things have any effect on this..

Author:  CaveCricket48 [ Wed Aug 19, 2009 11:36 pm ]
Post subject:  Re: Object Spawning Script not working

Everything in the ini is in order. When I tested the device I use to create the MOSRotating, it is created as it should. But when I add the Lua script by Grif, It doesn't show up.

Author:  Grif [ Thu Aug 20, 2009 12:57 am ]
Post subject:  Re: Object Spawning Script not working

Put this line into update (not inside any statements):
print(self.target.PresetName);

if it prints anything besides nil (the actor's presetname) then you can narrow down the error

if it prints nil then it's something with the target designation

Author:  CaveCricket48 [ Thu Aug 20, 2009 1:18 am ]
Post subject:  Re: Object Spawning Script not working

The print line didn't exactly help. But I found something interesting. When I removed the else self gib line, the MOSRotating didn't disapear. But when I pressed crouch, The shield MOSR popped up like it should, and then the game crashed.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/