|
FAQ
• Search • Login
|
|
Page 1 of 1
|
[ 9 posts ] |
|
Very strange Lua error...
Author |
Message |
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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: Attachment:
ScreenDump000.bmp [ 900.05 KiB | Viewed 2857 times ]
|
Sun Sep 27, 2009 2:53 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Sun Sep 27, 2009 3:09 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Very strange Lua error...
Ok, I fixed all those "if" statements, but I still get the same error.
|
Sun Sep 27, 2009 4:00 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
Re: Very strange Lua error...
Post the new script.
|
Sun Sep 27, 2009 4:34 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
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
|
Sun Sep 27, 2009 4:55 am |
|
|
Grif
REAL AMERICAN HERO
Joined: Sat Jan 27, 2007 10:25 pm Posts: 5655
|
Re: Very strange Lua error...
Well your end syntax is horrible, it's possible you missed on and it's still not checking correctly.
|
Sun Sep 27, 2009 4:58 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Very strange Lua error...
Checked all those end things, I'm pretty sure they're in the right place.
|
Sun Sep 27, 2009 5:44 am |
|
|
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
|
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.
|
Sun Sep 27, 2009 5:45 am |
|
|
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
|
Re: Very strange Lua error...
|
Sun Sep 27, 2009 1:45 pm |
|
|
|
|
Page 1 of 1
|
[ 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
|
|