Data Realms Fan Forums http://45.55.195.193/ |
|
Very strange Lua error... http://45.55.195.193/viewtopic.php?f=73&t=16674 |
Page 1 of 1 |
Author: | CaveCricket48 [ Sun Sep 27, 2009 2:53 am ] |
Post subject: | Very strange Lua error... |
This Lua script I made is attached to a MOPixel and is supposed to turn the closest actor (self.parent) within the defined distance into a "phoenix," meaning the target actor respawns when it dies. However, it gives a strange error when the target actor (self.parent) dies. Code: Code: function Create(self) self.respawned = false; self.gottarget = false; self.parent = nil; self.parentname = nil; local curdist = 10; for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist and actor.ClassName == "AHuman" then self.parent = actor; self.parent:FlashWhite(100); self.gottarget = true; end end end function Update(self) self.ToSettle = false; self.ToDelete = false; if MovableMan:IsActor(self.parent) then self.Pos = self.parent.Pos; self.Vel = Vector(0, 0); end if not(MovableMan:IsActor(self.parent)) and self.gottarget == false then self.ToSettle = true; self.ToDelete = true; self.LifeTime = 0; end if MovableMan:IsActor(self.parent) and not(self.parent:HasObject("Phoenix Respawner")) then self.parent:AddInventoryItem(CreateHDFirearm("Phoenix Respawner" , "CLMiniMods.rte")); end if MovableMan:IsActor(self.parent) and self.parent:IsPlayerControlled() == true then self.iscontrolled = true; end if MovableMan:IsActor(self.parent) and self.parent:IsPlayerControlled() == false then self.iscontrolled = false; end if self.gottarget == true and not(MovableMan:IsActor(self.parent)) then self.phoenixrespawn = CreateAHuman(self.parent); self.phoenixrespawn.Pos = self.Pos; self.phoenixrespawn.Team = self.parent.Team; self.phoenixrespawn:AddInventoryItem(CreateHDFirearm("Phoenix Respawner" , "CLMiniMods.rte")); MovableMan:AddActor(self.phoenixrespawn); self.parent = self.phoenixrespawn; self.respawned = true; end if self.respawned == true then if self.phoenixrespawn.iscontrolled == false then self.respawned = false; end end if self.respawned == true then if self.phoenixrespawn.Team == 0 and self.phoenixrespawn.iscontrolled == true then ActivityMan:GetActivity():SwitchToActor(self.phoenixrespawn,Activity.PLAYER_1,0); self.respawned = false; end end if self.respawned == true then if self.phoenixrespawn.Team == 1 and self.phoenixrespawn.iscontrolled == true then ActivityMan:GetActivity():SwitchToActor(self.phoenixrespawn,Activity.PLAYER_2,1); self.respawned = false; end end end Error: |
Author: | TheLastBanana [ Sun Sep 27, 2009 3:09 am ] |
Post subject: | Re: Very strange Lua error... |
Your problem lies in the way the Lua is parsed to be run. Code: if MovableMan:IsActor(self.parent) and not(self.parent:HasObject("Phoenix Respawner")) then This line, along with a few others, are going to cause errors. The program always checks every condition of an if statement before running the code. That means that in this case, even if self.parent no longer exists, it will try to check if it is holding the Pheonix Respawner. Move the object check to another if statement on another line. Do the same for any other if statements structured this way. |
Author: | CaveCricket48 [ Sun Sep 27, 2009 4:00 am ] |
Post subject: | Re: Very strange Lua error... |
Ok, I fixed all those "if" statements, but I still get the same error. |
Author: | TheLastBanana [ Sun Sep 27, 2009 4:34 am ] |
Post subject: | Re: Very strange Lua error... |
Post the new script. |
Author: | CaveCricket48 [ Sun Sep 27, 2009 4:55 am ] |
Post subject: | Re: Very strange Lua error... |
Code: function Create(self) self.respawned = false; self.gottarget = false; self.parent = nil; self.parentname = nil; local curdist = 10; for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if dist < curdist and actor.ClassName == "AHuman" then self.parent = actor; self.parent:FlashWhite(100); self.gottarget = true; end end end function Update(self) self.ToSettle = false; self.ToDelete = false; if MovableMan:IsActor(self.parent) then self.Pos = self.parent.Pos; self.Vel = Vector(0, 0); end if not(MovableMan:IsActor(self.parent)) then if self.gottarget == false then self.ToSettle = true; self.ToDelete = true; self.LifeTime = 0; end end if MovableMan:IsActor(self.parent) then if not(self.parent:HasObject("Phoenix Respawner")) then self.parent:AddInventoryItem(CreateHDFirearm("Phoenix Respawner" , "CLMiniMods.rte")); end end if MovableMan:IsActor(self.parent) then if self.parent:IsPlayerControlled() == true then self.iscontrolled = true; end end if MovableMan:IsActor(self.parent) then if self.parent:IsPlayerControlled() == false then self.iscontrolled = false; end end if self.gottarget == true then if not(MovableMan:IsActor(self.parent)) then self.phoenixrespawn = CreateAHuman(self.parent); self.phoenixrespawn.Pos = self.Pos; self.phoenixrespawn.Team = self.parent.Team; self.phoenixrespawn:AddInventoryItem(CreateHDFirearm("Phoenix Respawner" , "CLMiniMods.rte")); MovableMan:AddActor(self.phoenixrespawn); self.parent = self.phoenixrespawn; self.respawned = true; end end if self.respawned == true then if self.phoenixrespawn.iscontrolled == false then self.respawned = false; end end if self.respawned == true then if self.phoenixrespawn.Team == 0 and self.phoenixrespawn.iscontrolled == true then ActivityMan:GetActivity():SwitchToActor(self.phoenixrespawn,Activity.PLAYER_1,0); self.respawned = false; end end if self.respawned == true then if self.phoenixrespawn.Team == 1 and self.phoenixrespawn.iscontrolled == true then ActivityMan:GetActivity():SwitchToActor(self.phoenixrespawn,Activity.PLAYER_2,1); self.respawned = false; end end end |
Author: | Grif [ Sun Sep 27, 2009 4:58 am ] |
Post subject: | Re: Very strange Lua error... |
Well your end syntax is horrible, it's possible you missed on and it's still not checking correctly. |
Author: | CaveCricket48 [ Sun Sep 27, 2009 5:44 am ] |
Post subject: | Re: Very strange Lua error... |
Checked all those end things, I'm pretty sure they're in the right place. |
Author: | TheLastBanana [ Sun Sep 27, 2009 5:45 am ] |
Post subject: | Re: Very strange Lua error... |
I would highly suggest tabbing it properly. As is, I can't read the code well enough to diagnose the problem. |
Author: | CaveCricket48 [ Sun Sep 27, 2009 1:45 pm ] |
Post subject: | Re: Very strange Lua error... |
Tabbed. http://pastebin.com/m551fd2da |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |