function Create(self) self.Turret = {} self.Turret[5] = CreateACrab("Dragoon MG Mount") MovableMan:AddParticle(self.Turret[5]) self.Turret[5].Team = self.Team self.Turret[5].Offset = Vector(64,20); end
function Update(self) for i = 5, #self.Turret do if MovableMan:IsParticle(self.Turret[i]) == true then self.Turret[i].Vel.X = 0; self.Turret[i].Vel.Y = 0; self.Turret[i].RotAngle = self.RotAngle; self.Turret[i].Pos = self.Pos + self:RotateOffset(self.Turret[i].Offset) end end end
function Destroy(self) for i = 1, #self.Turret do if MovableMan:IsParticle(self.Turret[i]) == true then if self.Health < 1 then self.Turret[i]:GibThis() else self.Turret[i].ToDelete = true end end end end
This error keeps happening, any thoughts?
ERROR: MySaMs.rte/Actors/Tank/DragoonTank.lua:20: attempt to get length of field 'Turret' (a userdata value)
Fri Feb 09, 2018 1:25 am
CaveCricket48
Joined: Tue Jun 12, 2007 11:52 pm Posts: 13144 Location: Here
function Create(self) self.turretPart = {} self.turretOffset = {}
local actor = CreateACrab("Crab") actor.Team = self.Team MovableMan:AddParticle(actor)
local newIndex = #self.turretPart+1 self.turretPart[newIndex] = actor self.turretOffset[newIndex] = Vector(64,20); end
function Update(self) for i = 1, #self.turretPart do if MovableMan:IsParticle(self.turretPart[i]) then self.turretPart[i].Vel.X = 0; self.turretPart[i].Vel.Y = 0; self.turretPart[i].RotAngle = self.RotAngle; self.turretPart[i].Pos = self.Pos + self:RotateOffset(self.turretOffset[i]) end end end
function Destroy(self) for i = 1, #self.turretPart do if MovableMan:IsParticle(self.turretPart[i]) then if self.Health < 1 then self.turretPart[i]:GibThis() else self.turretPart[i].ToDelete = true end end end end
Fixed script. I tested with a "Crab" instead of "Dragoon MG Mount"
Issues:
- self.Turret is an actual existing variable, and you were trying to replace it with a table. No can do.
- You can't add custom variables to MOs (MovableObjects, which include actors, particles, etc.). " self.Turret[5].Offset " is no good.
- I don't know why you're starting at index 5 when adding the crab to the table
Things that worked but were changed:
- " MovableMan:IsParticle(self.turretPart[i]) " returns true, and "MovableMan:IsParticle(self.turretPart[i]) == true" also returns true. You don't need "X == true", just "X".
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