Need some help with for a loop through ammo-turrets
Posted: Mon Sep 13, 2021 9:53 pm
Hi all,
I'm trying to write some code that makes all turrets that shoot bullets accept different ammo types from my mod.
I tried plain adding ammo_categories to the attack_parameters, and it worked fine. But when I used a for loop to iterate through all ammo turrets (mainly for bob's), it doesn't. They still only fire base game bullets. From what I can see bob's turrets aren't really defined differently from the base game's.
My code is the following. Any help would be appreciated. Yes I know this code isn't perfectly compatible with other mods yet, but I'll get to it after it starts working.
I'm trying to write some code that makes all turrets that shoot bullets accept different ammo types from my mod.
I tried plain adding ammo_categories to the attack_parameters, and it worked fine. But when I used a for loop to iterate through all ammo turrets (mainly for bob's), it doesn't. They still only fire base game bullets. From what I can see bob's turrets aren't really defined differently from the base game's.
My code is the following. Any help would be appreciated. Yes I know this code isn't perfectly compatible with other mods yet, but I'll get to it after it starts working.
Code: Select all
local a = {"bullet"}
--add ammo types from my mod. this works.
for i, f in ipairs(ATF_calibers) do
table.insert(a,f)
end
--test code. this works fine on base game turret (it added all ammo types, base game bullets included)
--data.raw["ammo-turret"]["gun-turret"].attack_parameters.ammo_categories = a
--this is the for loop i use to add ammo_categories to all turrets. Doesn't work.
tur = data.raw["ammo-turret"]
for i, v in ipairs(tur) do
tur.v.attack_parameters.ammo_categories = a
end