Factory build checking functions, log spam reduction, and CSV export tools for BAR.
A common widget requirement involves checking whether a specific factory can produce a particular unit. The approach uses Spring.GetUnitDefID to resolve the factory ID, then iterates through the factoryDef.buildOptions array to find the target unit definition:
function CanFactoryBuild(factoryID, unitDefID)
local factoryDefID = Spring.GetUnitDefID(factoryID)
local factoryDef = UnitDefs[factoryDefID]
if not factoryDef then
return false
end
for _, buildOptionID in ipairs(factoryDef.buildOptions) do
if buildOptionID == unitDefID then
return true
end
end
return false
end
This function returns a simple boolean. Factories with buildOptions arrays require iteration. Factories without build capabilities return false immediately.
Widget development generates significant log output that buries actual errors. The community solution redirects verbose messages to separate output channels instead of the main game log. This keeps error messages visible and actionable during active development.
Players debugging custom widgets benefit from this approach. Without log filtering, error messages scroll past unreadable during matches.
An existing widget exports match history statistics to CSV format at game end. The data structure uses sequential dataframe entries at regular time intervals. This output serves as a practical starting point for match analysis and performance tracking.
Building useful tools requires understanding the underlying game systems. Communities that share working code help everyone level up faster.
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.