LuaEntity.priority_targets for Turrets

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
LeonSkills
Inserter
Inserter
Posts: 26
Joined: Mon Feb 11, 2019 12:37 pm
Contact:

LuaEntity.priority_targets for Turrets

Post by LeonSkills »

Currently the only way to check the priority targets of turrets is to call LuaEntity.get_priority_target(index) for increasing indices until an Index out of bounds error is raised (the amount of targets isn't able to be read either AFAIK).

A LuaEntity.priority_targets::array[LuaEntityPrototype] would be cleaner.

Code: Select all

local targets = entity.priority_targets
vs

Code: Select all

local targets = {}
local index = 0
while true do
  index = index + 1
  local success, target = pcall(entity.get_priority_target, index)
  if not success then break end
  table.insert(targets, target)
end
LeonSkills
Inserter
Inserter
Posts: 26
Joined: Mon Feb 11, 2019 12:37 pm
Contact:

Re: LuaEntity.priority_targets for Turrets

Post by LeonSkills »

Same issue with set/get_filter, but at least there a filter_slot_count exists.
User avatar
Fishbus
Inserter
Inserter
Posts: 25
Joined: Sat Sep 28, 2024 8:20 pm
Contact:

Re: LuaEntity.priority_targets for Turrets

Post by Fishbus »

I also would like this

get_priority_targets & set_priority_targets
User avatar
Fishbus
Inserter
Inserter
Posts: 25
Joined: Sat Sep 28, 2024 8:20 pm
Contact:

Re: LuaEntity.priority_targets for Turrets

Post by Fishbus »

LeonSkills wrote: Sat Dec 21, 2024 9:14 pm Currently the only way to check the priority targets of turrets is to call LuaEntity.get_priority_target(index) for increasing indices until an Index out of bounds error is raised (the amount of targets isn't able to be read either AFAIK).
I've used this to create 2 helper functions. For posterity in case anyone else comes along this post:

Code: Select all

function GetTargets(entity)
	local targets = {}
	local index = 0
	while true do
	  index = index + 1
	  local success, target = pcall(entity.get_priority_target, index)
	  if not success then break end
	  table.insert(targets, target)
	end
	return targets
end
and

Code: Select all

function SetTargets(targets, entity)
	 for i, v in pairs (targets) do
		entity.set_priority_target(i,v)
	 end
end
Post Reply

Return to “Modding interface requests”