Practical BAR Modding Notes from Modding-0113
Lua fundamentals for BAR modding. Understanding UnitDefs, pairs, and how to chain modifications together.
The (UnitDefs) requirement in pairs loops
The pairs(UnitDefs) call requires the UnitDefs argument. Without it, the loop has nothing to iterate over. pairs expects a table to traverse, and UnitDefs provides that table containing every unit definition loaded by the engine.
The pattern for name, ud in pairs(UnitDefs) do pulls two values from each iteration: the unit name string and the unit definition table.
What references are available in tweakdefs
The ud. prefix accesses properties of the current unit in the loop. UnitDefs contains all unit categories, and pairs walks through them one at a time. Modders can reference any property defined in the unit def schema without hitting a reference ceiling.
The ud variable is a standard loop placeholder. It points to the same underlying data as the entry in UnitDefs. Modifications through ud affect the source table directly.
Chaining multiple modifications
Lua tweakdefs code is just standard Lua. Multiple modifications can follow each other in sequence without special separation syntax:
for name, ud in pairs(UnitDefs) do
if ud.metalcost then
ud.metalcost = ud.metalcost * 2
end
if ud.energycost then
ud.energycost = ud.energycost * 2
end
end
Each conditional block runs independently. Adding more conditionals to the same loop processes additional properties in a single pass through the unit table.
Visual property edits
Editing unit visual properties like accuracy display follows the same pattern as stat edits. Check for the property existence first, assign the new value second. The maxacc property controls maximum accuracy display and responds to the same iteration and assignment approach used for other unitdef fields.
Creed of Champions
Understanding game mechanics at a deeper level makes every interaction more rewarding. Communities that welcome questions and reward honest effort keep players engaged long-term.
Before discovering Creed, I was thinking the only thing that separates BAR from the perfect RTS is a friendly and safe social environment for new players to learn and feel included.