Two lessons from building an idle-game framework in Godot 4: float drift and simulating balance (free MIT number class)

While building an idle/incremental framework for Godot 4.7, I ran into two problems worth sharing whether or not you use my code.

1. Big-number classes can break “can I afford it?”
A typical mantissa/exponent big-number class re-normalises with log()/pow() after every operation. In my first version, 15 + fifteen 1s gave 30.000000000000013 instead of 30. That’s harmless on screen, but a purchase that costs exactly 30 is compared against that value, so the check can go the wrong way.

My fix was to store values below 1e300 as plain floats (whole numbers up to 2^53 stay exact) and only switch to mantissa/exponent above that. I also tested 20,000 random floats through Godot’s text conversions ("%.16f", var_to_str/str_to_var, JSON, String.num_scientific, String.num), and none of them round-tripped every value bit-for-bit. So my saves store the raw 64-bit pattern with PackedByteArray.encode_double.

2. Simulate your economy before players do.
In a generator-style idle game, production is constant between purchases, so you can simulate events instead of frames: jump straight to the moment the next thing becomes affordable. With a greedy “best payback” player, 8 hours of play take about 2 seconds to compute on my PC.

On my demo it caught a prestige formula (square-root gain, +10% per point) that became a runaway loop: after about 4 hours the simulated player was resetting every 2–3 minutes. A cube root and a lower threshold fixed it.

The number class and formatter are free and MIT-licensed as Tickwork Lite: GitHub - trendnest0046-afk/tickwork-lite: Free MIT big numbers + number formatting for Godot 4 idle/incremental games (TickNum, TickFormat). Lite core of Tickwork. · GitHub

The full framework (simulator, saves, prestige, offline progress, demo game) is a paid asset on itch.io: Tickwork: Idle Game Framework + Balancing Simulator for Godot 4 by Terminator046

Tested on Godot 4.7.2. Built with AI assistance and covered by automated tests. Happy to discuss the approach either way.