FAForever Forums
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Login
    The current pre-release of the client ("pioneer" in the version) is only compatible to itself. So you can only play with other testers. Please be aware!

    Need a hand with a table

    Scheduled Pinned Locked Moved Modding & Tools
    2 Posts 1 Posters 134 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R Offline
      Resin_Smoker
      last edited by Resin_Smoker

      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

      Kykhu Oss https://youtu.be/JUgyGTgeZb8
      Unit Thrower https://youtu.be/iV8YBXVxxeI
      Beam Tentacle https://youtu.be/le5SNwHvC4c
      Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
      Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

      R 1 Reply Last reply Reply Quote 0
      • R Offline
        Resin_Smoker @Resin_Smoker
        last edited by

        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
        

        Kykhu Oss https://youtu.be/JUgyGTgeZb8
        Unit Thrower https://youtu.be/iV8YBXVxxeI
        Beam Tentacle https://youtu.be/le5SNwHvC4c
        Blackhole https://www.youtube.com/watch?v=D9NGQC5rr0c
        Resurection https://www.youtube.com/watch?v=WdbIQ4vHkMs

        1 Reply Last reply Reply Quote 0
        • First post
          Last post