BAR widget inter-communication and weapondefs tweak pitfalls

Widgets need to talk to each other and to the game rules. Getting Lua message passing right and understanding why weapon changes do not stick are two common developer headaches.

Tags: BAR widgets, lua messages, SendLuaRulesMsg, SendLuaUIMsg, weapondefs tweaks

Inter-widget communication with Lua messages

Widgets communicate through the SendLuaMessage system. The SpringRTS wiki inter-communications diagram shows the flow — widgets send messages through the unsynced control layer, and other widgets receive them through callins. This is the standard mechanism for sharing data between UI elements: for example, one widget tracking economy state and another displaying it on a custom panel.

SendLuaRulesMsg versus SendLuaUIMsg

These two functions serve different purposes despite similar names. SendLuaUIMsg communicates between UI-side widgets — things like button presses, display updates, and overlay changes. SendLuaRulesMsg sends messages from the game rules layer to the UI layer, meaning server-side game state changes that the UI needs to display. They are not interchangeable. Using the wrong one means your message never arrives at the intended recipient, and the failure is silent with no obvious error message.

Weapondefs tweaks that do not apply in-game

A frequent frustration: you tweak weapon damage and reload time in a tweakdef, the base64 string decodes correctly, and the game loads — but the modified unit fires at the vanilla rate anyway. The most likely cause is that the game's stat display reads from a different data path than the actual weapon definition used during combat. Weapondefs modifications through tweakdefs work for lobby stat displays but may not propagate correctly to the runtime engine, especially on complex units with multiple weapon types. The tweak changes what the lobby shows, not necessarily what the unit does in the match.

For reliable weapon modification, edit the actual weapondef entries in the unit files rather than relying on tweakdef overrides. The tweakdef system has limits on which fields propagate to the running game engine.

Creed of champions

Players who take the time to understand how the engine works bring deeper knowledge to team strategy. Creed of Champions welcomes technically curious players who share what they discover. Better teammates, better 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.

Advertisement