Page 1 of 1
LuaEntity.priority_targets for Turrets
Posted: Sat Dec 21, 2024 9:14 pm
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
Re: LuaEntity.priority_targets for Turrets
Posted: Sat Dec 21, 2024 10:36 pm
by LeonSkills
Same issue with set/get_filter, but at least there a filter_slot_count exists.
Re: LuaEntity.priority_targets for Turrets
Posted: Wed Jun 18, 2025 3:58 pm
by Fishbus
I also would like this
get_priority_targets & set_priority_targets
Re: LuaEntity.priority_targets for Turrets
Posted: Wed Jun 18, 2025 11:58 pm
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
Re: LuaEntity.priority_targets for Turrets
Posted: Mon Aug 11, 2025 4:37 pm
by Rseding91
I've added LuaEntity::priority_targets read for the next release.