LuaEntity.priority_targets for Turrets

LeonSkills
Inserter
Inserter
Posts: 27
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: 27
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: 36
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: 36
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
Rseding91
Factorio Staff
Factorio Staff
Posts: 15981
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: LuaEntity.priority_targets for Turrets

Post by Rseding91 »

I've added LuaEntity::priority_targets read for the next release.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Implemented mod requests”