Messing with tweakdefs and Lua unit edits is a staple of custom BAR lobbies. A few structural mistakes trip up nearly every modder. Here is what actually works.
Tags: BAR modding, lua tweaks, unit definitions, tweakdefs, base64, custom lobbies
The most common beginner mistake in BAR modding is assuming you can write to any value in a unitdef and have it work. Several values are read-only at runtime, defined by engine-side C++ code rather than Lua. You can read them, change them in a script, and nothing happens. The game silently ignores the assignment.
Recloak speed is a well-known example. The unit cloak definition exposes .mincloakdistance, .cancloak, .initcloaked, .cloakcost, and .cloakcostmoving. But recloak speed — how fast a unit re-cloaks after breaking stealth — simply does not exist as a writable field. You cannot add it by inserting a value into the def. It is not there in the source code itself.
A frequent pattern in shared tweak scripts uses two separate loops over UnitDefs — one to change costs, another to change something else. This works fine, but merging into a single pass is cleaner and marginally faster during lobby init. Instead of iterating the entire unit pool twice, handle every modification inside one for name, ud in pairs(UnitDefs) block.
Here is a working pattern that sets builder costs across the board:
for name, ud in pairs(UnitDefs) do
if ud.builder then
ud.metalcost = 1000
ud.energycost = 1500
ud.buildtime = 4600
end
end
One loop. Direct checks. No unnecessary string manipulation on unit names.
When sharing tweak configurations across a lobby, base64 encoding is the standard courier. You encode your tweak table on one machine, paste the string into chat, and the other side decodes and applies it. The encoding itself is straightforward, but two things regularly go wrong. First, the decoded structure must match exactly what the receiving script expects — a missing comma or a swapped order breaks the whole thing without a clear error message. Second, the replay site has a known search bug where some replays exist but do not show up in normal search results. If you are using tweak-based replays for teaching or review, do not assume they will be findable through the standard replay browser. Keep local copies.
Some float-around snippets look complete but are actually conceptual fragments — ideas someone wrote down thinking they would compile, never tested against the actual engine. The unit_cloak gadget code on the BAR GitHub is the real reference. If a tweak value does not appear there, it likely does not exist in the engine. Before spending hours debugging a tweak that should work, verify the target field is actually defined in the source gadgets.
Clear information, clean execution, and low-drama learning habits help entire teams improve. The Creed of Champions community is built on exactly that kind of disciplined cooperation — competitive play without the blame game. People who share working tweaks and help each other debug are the ones everyone wants on their team.
[Crd] Gaming actually fulfills a human purpose here — cooperation, mutual upbuilding, fun and striving for greatness together. Instead of random anonymity, you meet, learn from, and enjoy real people.