OpenTTD AIs and Game Scripts • AIAccounting doesn't work properly
I'm having problem with AIAccounting() object, here is pseudo code:
Code:
local costs = AIAccounting();if (!BuildRoadRoute(route)) {Log.Warning(costs.GetCosts(), "cash has been wasted to failed road route");return false;}
I don't have exact repro steps but if you want I may be able to create them, but I think you'll know where the problem is.
In the above snippet BuildRoadRoute is very lengthy function that calls multiple functions which in turn call other functions and so on, various API's that expend cash are used not only in this top level function but also in other functions down the stack.
I suspect this the problem why costs.GetCosts() shows really silly numbers that make no sense, such as telling over 1M cash has been spent while I only have 400K on hand or so. Sometimes it does seemingly report correct numbers but most of the time it say I spent more that what I have.
What could be the problem?
I tried using the object in very simple snippets without any nesting and in that case it appears to work fine. However it doesn't work when there is a lot of stuff going on.
And also this function above calls functions that are across multiple files and classes, so maybe this could be the cause as well...
edit:
Here is sample screenshot, it says I spent more than what I actually did, (sometimes it says 1M sometimes 600K there is no rule, road route doesn't cost that much):
Statistics: Posted by GoldMine — 25 Feb 2026 19:51
Discussion in the ATmosphere