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



Reply to topic  [ 9 posts ] 
 Object Spawning Script not working 
Author Message
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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


Wed Aug 19, 2009 10:55 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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...


Wed Aug 19, 2009 11:07 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Object Spawning Script not working
http://pastebin.com/m541777af


Wed Aug 19, 2009 11:19 pm
Profile
happy carebear mom
User avatar

Joined: Tue Mar 04, 2008 1:40 am
Posts: 7096
Location: b8bbd5
Reply with quote
Post 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).


Wed Aug 19, 2009 11:19 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Wed Aug 19, 2009 11:30 pm
Profile
User avatar

Joined: Thu Mar 06, 2008 10:54 pm
Posts: 1360
Location: USA
Reply with quote
Post 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..


Wed Aug 19, 2009 11:33 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Wed Aug 19, 2009 11:36 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post 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


Thu Aug 20, 2009 12:57 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post 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.


Thu Aug 20, 2009 1:18 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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.031s | 13 Queries | GZIP : Off ]