New tweakdefs fail when subtables do not exist, and modifying weapon damage requires navigating nested definitions correctly.
Tags: BAR tweakdefs, required subtables, tweakunits weapon damage, T1 constructors
New BAR tweakdefs fail silently if expected subtables are missing from a unit definition. The most common culprits are buildoptions, customparams, weapondefs, and weapons. If you try to write to ud.customparams on a unit that has never set customparams, the write goes nowhere. The fix is to check and create the subtable before writing:
if not ud.customparams then
ud.customparams = {}
end
ud.customparams.myvalue = "something"
This applies to all nested writes in tweakdefs. Missing subtables are the single biggest cause of silent tweakdef failures.
Modifying weapon damage on existing units is cleaner through tweakunits than tweakdefs. The pattern targets specific weapon names inside the weapondefs subtable:
{
corcrwh = {
weapondefs = {
krowlaserh = { damage = { default = 90 } },
dragonmawh = { damage = { default = 6, subs = 3 } },
dragon_missileh = { damage = { vtol = 76 } },
},
},
}
Damage takes different keys for different target types — default is the base damage, while keys like subs and vtol override damage for specific unit categories. Set both the base and category-specific values if you want consistent behavior.
Adding the same build options across multiple commanders or builders uses a simple loop:
local t1ConList = {"armck","armcv","armbeaver","armca","armcs",
"corck","corcv","cormuskrat","corca","corcs",
"legck","legcv","legaceb","legca","legcs"}
for i, conName in ipairs(t1ConList) do
table.insert(UnitDefs.armcom.buildoptions, conName)
end
This pattern scales cleanly — just add unit names to the list. All T1 constructors across all three factions get added to the commander build menu in one pass. Test with and without Legion active, as some unit names change under certain mod configurations.
Once your tweak works locally, encode it for lobby sharing. Paste the Lua table into a base64 encoder, set URL encoding mode, and remove any trailing equals signs from the output. The trailing equals sign breaks decode on the receiving end. This is a consistent failure point — always check the encoded string before sharing.
Well-documented, working tweak scripts help the entire community learn faster. Creed of Champions values players who share their code and explain what it does. Win with skill, teamwork, and respect.
[Crd] Having a space like here that offers a community, trainings, events, and the guarantee to not be judged or insulted by fellow members is really precious.