Need a hand with a table
-
Recently I've been working on importing the intel cone scripts into defaultcomponents.lua
InitializeRadarCone = function(self) if myDebug then WARN('InitializeRadarCone') end -- Int the entities table self.RadarConeEntitiesTable = {} -- Set up local variables from spec local bp = self:GetBlueprint() local bone = nil local radius = bp.Intel.RadarRadius local rotate = false local start = true if myDebug then WARN(' bone: ', bone,' radius: ', radius,' rotate: ', rotate,' start: ', start) end if radius > 0 then if myDebug then WARN('radius > 0') end local counter = 1 local loopFlag = true while not self:BeenDestroyed() and counter <= radius and loopFlag do if myDebug then WARN('LOOP') end -- Create a radar arc thats approx 45 degrees and is roughly the radius needed local angle = math.ceil(counter / 3.14) if counter + angle < radius then if myDebug then WARN(' Counter + angle < radius') end -- Attach the entity to parent local radEnt = import('/lua/sim/Entity.lua').Entity({Owner = self,}) if myDebug then WARN(' entity created') end radEnt:AttachBoneTo( -1, self, bone or 0 ) if myDebug then WARN(' entity attached') end table.insert(self.RadarConeEntitiesTable, radEnt) if myDebug then WARN(' entity inserted into tbl: ', table.getn(self.RadarConeEntitiesTable)) end self.Trash:Add(radEnt) if myDebug then WARN(' entity added to trash') end -- Offset the entities so they create a cone from the parent radEnt:SetParentOffset(Vector(0,0, counter)) if myDebug then WARN(' entity offset') end -- Set who can view the entities intel radEnt:SetVizToFocusPlayer('Always') radEnt:SetVizToAllies('Always') radEnt:SetVizToNeutrals('Never') radEnt:SetVizToEnemies('Never') if myDebug then WARN(' focus set') end -- Initalize intel radEnt:InitIntel(self:GetArmy(), 'Radar', angle) if myDebug then WARN(' intel initialized') end else loopFlag = false if myDebug then WARN(' flipping flag to end loop early') end end if loopFlag then counter = counter + 1 if myDebug then WARN(' counter increased') end end end if myDebug then WARN(' end loop') end if start then if myDebug then WARN(' starting on') end -- Initialize and enable intel types self:EnableRadarCone() end if bone and rotate then if myDebug then WARN(' rotating') end -- Rotate the radar cone if a bone is provided self.Trash:Add(CreateRotator(self.Owner, self.Bone, 'y', nil, 0, 999, 36)) end end end, EnableRadarCone = function(self) if myDebug then WARN('EnableRadarCone') end if not self.RadarConeActive and table.getn(self.RadarConeEntitiesTable) > 0 then if myDebug then WARN(' Radar cone not active, turning them on') end for k, v in self.RadarConeEntitiesTable do self:EnableIntel({self.RadarConeEntitiesTable[k]}) end self.RadarConeActive = true end end, DisableRadarCone = function(self) if myDebug then WARN('DisableRadarCone') end if self.RadarConeActive and table.getn(self.RadarConeEntitiesTable) > 0 then if myDebug then WARN(' Radar cone active, turning them off') end for k, v in self.RadarConeEntitiesTable do self:DisableIntel({self.RadarConeEntitiesTable[k]}) end self.RadarConeActive = false end end,
But keep running into the issue where it says its expecting a string instead of a table. Which makes no sense when the data in the "RadarConeEntitiesTable" , are just other tables of entities I've just created.
Error Log...
WARNING: Error running OnStopBeingBuilt script in Entity uel0101 at 15ec6c08: string expected but got table stack traceback: [C]: in function `EnableIntel' ...faforever\gamedata\lua.nx2\lua\defaultcomponents.lua(1057): in function `EnableRadarCone' ...faforever\gamedata\lua.nx2\lua\defaultcomponents.lua(1041): in function `InitializeRadarCone' ...faforever\gamedata\lua.nx2\lua\defaultcomponents.lua(1189): in function `EnableUnitIntel' ...faforever\gamedata\lua.nx2\lua\defaultcomponents.lua(959): in function `OnStopBeingBuilt' ...gramdata\faforever\gamedata\lua.nx2\lua\sim\unit.lua(2329): in function <...gramdata\faforever\gamedata\lua.nx2\lua\sim\unit.lua:2316> ...orever\gamedata\lua.nx2\lua\sim\units\mobileunit.lua(123): in function <...orever\gamedata\lua.nx2\lua\sim\units\mobileunit.lua:122> ...data\lua.nx2\lua\sim\units\uef\tconstructionunit.lua(43): in function <...data\lua.nx2\lua\sim\units\uef\tconstructionunit.lua:42>
Which is pointing to...
EnableRadarCone = function(self) if myDebug then WARN('EnableRadarCone') end if not self.RadarConeActive and table.getn(self.RadarConeEntitiesTable) > 0 then if myDebug then WARN(' Radar cone not active, turning them on') end for k, v in self.RadarConeEntitiesTable do self:EnableIntel({self.RadarConeEntitiesTable[k]}) end self.RadarConeActive = true end end,
Something in the For-Do is not liking the table or how its being presented here. Gone through about a dozen variations of this with the exact same error each time. The table i know for a fact is populated with my entity data, as i can run table.getn and see the exact number of entities within it.
Anyone see something I'm missing before i drink myself to death ?
Cheers!
Resin
-
Pulling my head from my arse usually helps.
Bad script...
for k, v in self.RadarConeEntitiesTable do self:EnableIntel({self.RadarConeEntitiesTable[k]}) end
Should be...
for k, v in self.RadarConeEntitiesTable do v:EnableIntel('Radar') end