Data Realms Fan Forums
http://45.55.195.193/

Unkown Lua Error *Fixed
http://45.55.195.193/viewtopic.php?f=73&t=16352
Page 1 of 1

Author:  CaveCricket48 [ Tue Aug 25, 2009 3:11 pm ]
Post subject:  Unkown Lua Error *Fixed

Code:
ERROR: HeadCrab.rte/Control.lua:3: 'then' expected near '='

I'm not completely sure what this means, and my attampts at fixing aren't successful. My script is below.

Code:
function Update(self)
   self.targetcontrol = false;
   if self.target:GetController():IsState(Controller.WEAPON_FIRE) and self.targetcontrol = false then
   local curdist = 50;
   for actor in MovableMan.Actors do
      local dist = SceneMan:ShortestDistance(self.Pos,actor.Pos,true);
      if dist.Magnitude < curdist and actor.ID ~= self.ID then
         self.target = actor;
      self.targetcontrol = true;
      end
   end
end

   if self.target:IsDead() then
   self.GetsHitByMOs = 1;
   self.HitsMOs = 1;
   self.targetcontrol = false;
   end

   if self.targetcontrol = true then
   self.GetsHitByMOs = 0;
   self.HitsMOs = 0;
   self.Pos = self.target.Pos;
   end

   if self.target:GetController():IsState(Controller.HOLD_LEFT) and self.targetcontrol = true then
   self.target:GetController():IsState(Controller.HOLD_LEFT)
   end

   if self.target:GetController():IsState(Controller.HOLD_RIGHT) and self.targetcontrol = true then
   self.target:GetController():IsState(Controller.HOLD_RIGHT)
   end
end


This script is supposed to take control of the left and right movement of the closest actor within 50 pixels when fire is pressed. And this is attached to an actor.

Author:  Duh102 [ Tue Aug 25, 2009 3:26 pm ]
Post subject:  Re: Unkown Lua Error

You put "self.targetcontrol = false" in an if/then/else statement. You want "self.targetcontrol == false"
= is setting
== is equality comparison.

EDIT: This applies to all of them that you have "if something = something". They should always be "if something == something" if you're doing a comparison.

Author:  CaveCricket48 [ Tue Aug 25, 2009 3:52 pm ]
Post subject:  Re: Unkown Lua Error

Thanks, that worked.

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