BAR widget development: finding commanders and map-specific code

Cycle UnitDefs with pairs() to access customparams like iscommander, and understand why map-specific LuaGaia code is discouraged.

Tags: bar widgets, luaui, customparams, iscommander, lua beginners, widget development

Identifying commander units

All commanders in BAR carry iscommander = true in their customparams table. To find them, cycle through UnitDefs using pairs(). Direct index access does not work on nested customparams, so iteration is required. This tagging convention is the future-proof way to identify commanders, since modders adding new commander units should follow the same pattern.

Map-specific LuaGaia widgets

Writing widgets or gadgets tied to a specific map using LuaGaia is technically possible but strongly discouraged. Map-specific code creates sync issues when players with different mod configurations join the same game. Keep logic general and use mod options for behavior changes instead of hardcoded map conditions.

Sync errors in modded games

When running modded matches and sync errors appear, the debugging path starts with identifying which tweakdefs and modoptions are active in the lobby. Replicate the error without mods first. If the error disappears, the problem lives in the mod configuration. Create a support report listing all active tweakdefs and modoptions so others can reproduce the issue.

Creed of Champions

Widget developers who share their code and explain their design choices help the entire modding community grow. Creed of Champions welcomes players who contribute knowledge back to the community, whether through code, guides, or patient explanations. Everyone starts somewhere, and good communities remember that.

The first and only community I have seen that actually holds up to its values. I have not had a single bad experience here.

Advertisement