Fixing tweakdef crashes and setting unit limit categories in BAR

Beyond All Reason players using Base64 tweak codes hit the same crash pattern. The game crashes with a script error when the tweak structure does not match what the engine expects. Meanwhile, players building unit limit systems through gadgets need to pass data correctly between the lobby and their custom code.

Tags: beyond all reason, tweakdef troubleshooting, windmill energy, windgenerator, maxthisunit, unitlimit categories, gadget modding

Why tweakdef Base64 codes crash the game

A common mistake wraps the tweak table in a return statement like you would use in a normal Lua file. Neither tweakdefs nor tweakunits expects a return value. The tweakunits entry is the table itself, directly merged into UnitDefs. The tweakdefs system accesses UnitDefs directly.

Base64 code that returns a table causes a silent failure that becomes a crash when the game tries to process the malformed input.

Dynamic unit limits with customparams

Tracking unit categories like mex counts across all players works through customparams on unit definitions. Add a parameter like unitlimitcategory = "Mexes" to every mex type. The gadget reads these parameters and enforces the global limit.

This approach avoids dynamically changing maxthisunit values on every unit event. The built-in customparam system carries the category data with each unit definition.

Windmill energy output limits

The windgenerator parameter caps windmill production at 25 energy by default. Raising it above 25 produces no effect because the engine hard-caps wind energy at that value. Lowering it does reduce output proportionally.

If you need windmills producing more than 25 energy, the cap lives in the engine itself and requires a different approach than simple parameter adjustment.

Clean code prevents crashes

Tweakdef failures cascade when multiple malformed entries accumulate. The fix is always the same: correct the structure, remove the return statement, and test in a custom match before applying to actual games.

[Crd] I love being able to communicate with my team, getting and sharing tips and constructive feedback on gameplay, and having a good spirited community.