incrementalKit
Everything an idle, incremental, clicker or upgrade-shop game needs between "earn" and "spend": data-driven upgrades with nine price curves and exact bulk buying, stats that add up from upgrades, milestones and prestige, currencies with earning multipliers, prestige / rebirth with its own shop, generators that earn per second while playing and while away (with a welcome-back screen), milestones and records, per-player saves that are safe in multiplayer, events, and styled screens (shop, prestige, welcome back, milestones, toasts, hints, a currency HUD that rolls up and pops) in nine looks switched with one call.
local Inc = require("incrementalKit.inc")
Version 1.2.0. Uses three single modules from other kits, each installed as one record: saveKit's store (per-player storage), menusKit's icons and productionKit's numbers (the five base number styles; incrementalKit.numbers adds si, myriad, kanji and grouped on top). Installing incrementalKit brings those three modules along and nothing else of those kits (no package-wide dependencies), so the games that install it stay small and their own kits update freely.
1.2.0:
- Requirements read as sentences. A locked card says what to do, not raw data: "Reach 250 m deep (best: 76 m)", "Upgrade Miner to level 3 (now 0)", "Buy Coin Drone first", "Earn 1M Coins in total (so far 2.4K)", "Ascend once to unlock this", 'Earn the milestone "Millionaire"'. Records, counters and stats take a display name, a unit and an optional goal sentence from setup:
records = { bestDepth = { name = "Deepest dive", unit = "m", goal = "Reach {want} deep" } }(countersandstatswork the same way; a plain string is just the name). An id with no entry reads as words (bestFallbecomes "Best fall"). Any single requirement can carry its owntext(orlabel): a string with{want},{have}and{name}filled in, orfunction(have, want, name) return "..." end. Units sit right after the number for%,xand/..., with a space otherwise. - economyKit wallets, where they fit.
Inc.useEconomyKit({ gems = "gems" }, require("economyKit.economy"))keeps the named kit currencies in the player's economyKit wallet (per player, saved and authoritative in economyKit's bank), and every kit call (balance,earn,give,spend,canAfford, the shops and requirements) goes through it unchanged.Inc.useWallet(currency, { balance, spend, give, whole })does the same for any other wallet, andInc.walletOf(currency)says which one a currency uses. Gains go throughEconomy.grantwith reason"incrementalKit"(allow it inEconomy.setup{ clientGrants = ... }), spends throughEconomy.spend; fractions wait until they add up to a whole unit, and prestige never resets a bridged currency. It is opt-in and the game passes economyKit's module in, so incrementalKit takes no dependency on economyKit and its install stays the three modules above. Why the idle currencies stay in the kit: economyKit's bank takes whole numbers only (at most 1e9 per request, capped by each currency'smax), answers asynchronously, and accepts client grants only for reasons the game allows at a rate limit; an idle game's soft and prestige currencies earn fractions many times a second, grow to 1e300, are predicted locally for the roll-up and reset on prestige. Routing those through the bank would round away the early game, cap the late game and flood the bank, so economyKit fits a game's premium, whole-number currency (gems sold in an economyKit shop), not the core idle loop. - Gamepad focus navigation. The shop, prestige, milestones and welcome-back screens focus their first buy / ascend / claim button when they open or change tab; the d-pad (and the arrow keys) walk every enabled button and wrap round, A / Enter / Space presses it, LB / RB switch tabs, B closes.
UI.nav(step),UI.focusList()andUI.focusFirst()are there for a game's own screens.
1.1.0: the kit restarts itself every play session from the last Inc.setup (a game may call setup once per module lifetime: leaving play and pressing Play again reloads the save, closes any screen left open and respawns the host); the HUD's "+N" pop labels no longer carry a pointerEvents style (a UI validation warning); the install closure is down to the three modules above; the four extra number styles live in incrementalKit.numbers instead of a patched productionKit copy.
Guides
- How to make an idle game with upgrades and prestige (
how-to-make-an-idle-game-with-upgrades-and-prestige): every part of the kit, how it fits together, and the choices (curves, formulas, offline rules, looks). - Example: make a cookie-clicker style idle game with rebirth (
example-make-a-cookie-clicker-style-idle-game-with-rebirth): an empty world to a small playable clicker, step by step.
Open them in the editor's Docs panel, with zero guides read <name> in the shell, or an agent's guides tool.
First example
-- a component on any entity in your scene
local Inc = require("incrementalKit.inc")
function awake()
Inc.setup({
currencies = { coins = { name = "Coins" }, stars = { name = "Stars", kind = "prestige" } },
upgrades = {
{ id = "click", name = "Better Clicks", baseCost = 10, effect = { stat = "clickPower", op = "add", perLevel = 1 } },
{ id = "robot", name = "Robot", baseCost = 25, produces = { currency = "coins", perSecond = 1 } },
},
stats = { clickPower = 1 },
prestige = { currency = "stars", from = "coins", formula = "sqrt", divisor = 10000 },
})
Inc.ui.setLook("cartoon")
end
-- call from your own click / gameplay code
local function onTap()
Inc.earn("coins", Inc.stat("clickPower"), "click")
end
Press Play: a currency HUD appears top-left with Upgrades / Prestige / Milestones buttons top-right. The kit starts its own host the first time it is used in play (it ticks generators, autosaves, draws the screens and routes their clicks), so nothing else needs placing.
The API
Setup and data
| Call | What |
|---|---|
Inc.setup(opts) | currencies, upgrades, milestones, stats, prestige, offline, start (starting balances), numbers (style), namespace (save slot name), version + migrations, records / counters / stats (display names, units and goal sentences for requirement text), autosave (seconds). Re-callable. |
Inc.defineUpgrade(u) / Inc.defineMilestone(m) | Add one after setup. |
Inc.on(event, fn) / Inc.off(handle) | Events: bought, earned, spent, prestige, milestone, unlock, offline, claimed, record, loaded, changed, hint. |
Inc.rev() | Changes whenever anything visible changes (redraw your own UI on it). |
An upgrade: { id, name, description, icon, currency, baseCost, curve, curveParams, maxLevel, effect, produces, requires, category, shop = "main" | "prestige", hidden, secret, resetsOnPrestige }.
effect = { stat, op = "add" | "mul" | "pct" | "pow", perLevel, label }, or a list of them, orfunction(level, Inc) return { stat = amount } end.add: +perLevel per level.mul: x perLevel per level (compounding).pct: +perLevel % per level (additive).pow: raises the stat's exponent by perLevel per level.
produces = { currency, perSecond }(or a list): a generator, earning perSecond per level.requires:{ upgrade = "id", level = n },{ upgrades = { a = 3, b = 1 } },{ milestone = "id" },{ prestiges = n },{ record = "bestDistance", atLeast = 1000 },{ records = { name = v } },{ stat = "x", atLeast = v },{ currency = "coins", total = v }(lifetime earned),{ counter = "runs", atLeast = n }, a function, or a list of any of these (all must hold). Any of them may carrytext = "Dive below {want} (best: {have})"(or a function) to word it itself; otherwise the shop builds a sentence from the names and units given to setup.
A milestone: { id, name, description, icon, when = <same as requires>, reward = { currency, amount } | { upgrade, levels }, effect = <same as an upgrade's, applied once>, resetsOnPrestige }. Shorthand: put the condition keys on the milestone itself ({ id = "far", record = "bestDistance", atLeast = 1000 }).
A currency: { name, kind = "soft" | "premium" | "prestige", icon, color, hidden }.
Stats
Inc.stat(name) = (base + all adds) * all muls / pcts, then ^ (1 + all pows), from upgrades and reached milestones; Inc.stats() lists them. Base values come from stats = { name = base | { base, name, min, max } }. Names the kit itself reads:
| Stat | Default | Used for |
|---|---|---|
earn | 1 x prestige multiplier | every Inc.earn |
earn.<currency> | 1 | earnings of one currency |
source.<source> | 1 | earnings from one source ("tap", "distance", "idle" for generators ...) |
gen.<upgradeId> | 1 | one generator's output |
offline | 1 | offline efficiency multiplier |
offlineHours.mul | 1 | offline time-limit multiplier |
prestigeGain.mul | 1 | prestige gain multiplier |
Any other name ending in .mul also starts at 1; everything else starts at 0.
Currencies and earning
| Call | What |
|---|---|
Inc.earn(currency, amount, source?) | Applies earn x earn.<currency> x source.<source> and returns the amount credited. |
Inc.give(currency, amount, source?) | Adds with no multipliers (rewards, refunds). |
Inc.spend(currency, amount, reason?) / Inc.canAfford | Spend if possible. |
Inc.balance(c), Inc.earned(c) | Held; lifetime and this-run totals. |
Inc.multiplier(c, source?) | The multiplier earn would apply. |
Inc.currencies(), Inc.currency(id) | Definitions. |
Upgrades and bulk buying
| Call | What |
|---|---|
Inc.quote(id, amount) | amount = 1, 10, 25, any number, or "max": { count, cost, affordable, maxed, locked, level, nextLevel, currency }. The cost is the exact sum of the per-level prices, capped at maxLevel. |
Inc.buy(id, amount) | Returns ok and the quote, or false and "locked" / "maxed" / "poor". |
Inc.cost(id), Inc.level(id), Inc.setLevel(id, n) | Price of the next level; level; set it. |
Inc.isUnlocked(id), Inc.progressOf(conds) | Requirements met; progress { done, share, text }. |
Inc.upgrades({ shop, category }), Inc.categories(shop) | Lists. |
Inc.effectText(id, levels) | "+1 Push Power", "x2 Coins", "+3/s Coins". |
Price curves
Pick one per upgrade with curve = "<name>" and curveParams; baseCost is the first level's price. require("incrementalKit.curves") gives cost, total, maxAffordable, list, and define(name, fn) for your own named curve.
| Curve | Price of level n → n+1 | Params (default) | Feels like |
|---|---|---|---|
linear | base + step·n | step (= base) | calm, predictable |
exponential | base · rate^n | rate (1.15) | classic idle: 1.07 gentle, 1.15 Cookie Clicker |
polynomial | base · (n+1)^power | power (2) | prestige shops |
fibonacci | base · F(n+2): 1, 2, 3, 5, 8 … | ~x1.618 a level | |
stepped | base · rate^n · jump^⌊n/every⌋ | rate (1), jump (10), every (10) | clear tiers |
softcap | logistic S-curve from base to max | max (base·1000), mid (25), steep (0.2) | buy forever |
superexp | base · rate^n · accel^(n(n−1)/2) | rate (1.15), accel (1.01) | a wall that forces prestige |
constant | base | consumables | |
custom | your function(n, params) or curveParams.table = { prices } | anything |
Aliases work: classic, geometric, tiered, logistic, soft-capped, super-exponential, quadratic, fib …
Prestige
prestige = { currency, from, formula, divisor, scale, threshold, basis, bonusPer, bonusFrom, multiplier, resets, resetRecords, minGain, name, verb }.
formula:"sqrt"(scale·√(earned/divisor)),"cbrt","log"(scale·(log10(earned/divisor)+1) once earned ≥ divisor),"linear"(scale·(earned − threshold)/divisor over the threshold), orfunction(earned, Inc).basis:"run"(default: whatfromearned since the last prestige) or"lifetime".- Permanent multiplier: every point gives
bonusPer(0.1 = +10%) on all earnings, counted from points earned (bonusFrom = "earned", spending them in the prestige shop does not hurt) or held; or your ownmultiplier = function(Inc). - Resets: the currencies in
resets(default{ from }), every upgrade withresetsOnPrestige(default: main-shop ones), milestones markedresetsOnPrestige, this run's totals, andresetRecords. - The prestige shop: upgrades with
shop = "prestige"(priced in the prestige currency, never reset).
Inc.prestigePreview() → { can, gain, basis, next (earnings for one more point), multiplier, newMultiplier, resets = { currencies, upgrades }, prestiges }. Inc.prestige() does it. Inc.prestiges() counts them.
Idle and offline earnings
Inc.idleRate(currency) / Inc.idleRates() is per-second production (all multipliers, through source.idle). Generators pay out every frame while playing. When a player returns, time away (wall clock, from their saved lastSeen) pays rate x min(away, maxHours x offlineHours.mul) x efficiency x offline; offline = { enabled, maxHours = 8, efficiency = 0.5, minSeconds = 60 }. Inc.offlinePending() shows it, Inc.claimOffline(mult?) collects (mult 2 for a "double it" button), Inc.simulateAway(seconds) tests it. The welcome-back screen opens by itself.
Milestones, records, counters
Inc.record(name, value) keeps the best (true when it is a new best), Inc.best(name); Inc.count(name, delta) / Inc.counter(name) for lifetime counters; Inc.milestones() lists { def, done, at, progress }; Inc.hasMilestone(id). Milestones are checked after every change and fire a toast.
Big numbers
Inc.format(n, style?), Inc.setNumberStyle(style) (saved per player), Inc.numberStyles(); the formatter itself is Inc.numbers (require("incrementalKit.numbers"): format, rate, delta, duration, percent, grouped, setStyle, STYLES, INFO). Setting a base style also sets productionKit's, so a game using both kits writes numbers one way.
| Style | 12,340,000,000,000 reads |
|---|---|
short | 12.3T (K M B T Qa Qi Sx … up to 1e303) |
letters | 12.3T, then aa, ab … zz |
scientific | 1.23e13 |
engineering | 12.3e12 |
words | 12.3 trillion |
si | 12.3T (k M G T P E Z Y R Q) |
myriad | 12.3chō (Japanese 10^4 groups in romaji: man, oku, chō, kei …) |
kanji | 12.3兆 (needs a CJK font) |
grouped | 12,340,000,000,000 |
Saving and multiplayer
Each player's progress is saved in their own data store (runtime_data.player(id) through saveKit's store) under incrementalKit/<namespace>, a few seconds after any change, on prestige, on claiming offline earnings, and when play stops; it is back when they return. Each machine runs the kit for its own player only and the engine refuses writes to anyone else's store, so several players in one world each keep their own game and nobody's actions can change another's progress. Call Inc.earn / Inc.buy on the machine of the player who earned or bought (in a component, only for the local player: if Inc.isMine(player) then ... end).
Inc.card()/Inc.cardOf(userId): a public card (name, prestiges, records, lifetime totals) for leaderboards.Inc.save(),Inc.status()("memory"until the player's identity arrives, then"ready"; progress made before carries over),Inc.reset().Inc.useStore(store)/Inc.memoryStore(): save somewhere else (tests, a simulated second player).versionandmigrations = { [1] = function(save) ... end }upgrade old saves.
Screens and looks
Inc.ui:
| Call | What |
|---|---|
setLook(name, overrides?) | One of the nine looks; `overrides = { colors = { accent, buy, panel, ink, ... }, font = "anton" |
| `open("shop" | "prestige" |
hint(text, { once, duration, icon }) | A teaching bubble at the bottom (once per player with once). |
toast(text, { sub, icon, color, duration }) | A message card at the top. |
showHud(bool), setBulk(n) | |
configure({ hud, hudButtons, toasts, autoWelcome, autoHints, shopTitle, prestigeTitle, milestonesTitle, welcomeTitle, bulk, hudCorner, doubleOffline = { currency, cost }, keys }) | |
look() | Current look id and its palette, fonts and builders, to style your own UI to match. |
shopData(shop, bulk), build(name, w, h) | Everything a screen shows, or its widget tree, for a game that draws its own. |
| Look | Character |
|---|---|
clean | bright modern cards, soft shadows, rounded |
cartoon | thick ink outlines, chunky offset shadows, springy bounce |
pixel | hard 8-bit frames, square buttons, stepped motion, monospace |
neon (sci-fi) | chamfered glass over deep space, cyan glow, scanlines |
parchment (fantasy) | aged scroll, inked borders, serif italics, wax-seal buttons |
papercraft | paper layers, washi tape, dashed stitching, a hand-made tilt |
minimal | black on white, hairlines, spaced capitals, one red accent |
candy (arcade) | bubblegum gradients, candy stripes, glossy jelly buttons |
luxe | black lacquer and gold leaf, serif capitals |
require("incrementalKit.looks").define(name, base, spec) adds your own.
Input. Mouse and touch press any button; the d-pad and the arrow keys move focus through the open screen's buttons (the first buy button is focused when a screen opens) and Enter / Space / A press. The host adds Esc / Backspace / pad B to close, Q / E and LB / RB to switch tabs, 1-4 and pad Y for the bulk amount, B and P to open the shop and prestige screens (configure({ keys = false }) turns these off, setup({ hotkeys = false }) only the B / P toggles). Screens under 640 points wide stack cards with full-width buy buttons and stack the HUD.
First minute. Hints point a new player at the shop the first time something is affordable, and at prestige the first time it pays; affordable buy buttons glow and pulse, and the shop button and tabs carry a green dot.
What it ships
| Part | What |
|---|---|
inc.module | The API above. |
curves.module | The price curves and bulk maths. |
numbers.module | The nine big-number styles (productionKit.numbers plus si, myriad, kanji, grouped). |
ui.module | The screens. |
looks.module | The nine looks. |
icons.module | SVG icons (coin, gem, star, shard, bolt, gear, pickaxe, clock, crown, rocket, flame, shield, heart, trophy, lock, sparkle, chart, magnet, boot, dice, stairs, ragdoll, hand, factory, tree, moon …) plus menusKit's. |
IncHost.component | The host the kit spawns in play (again every play session). |
| two guides | See Guides. |
Performance
Measured in the demo (13 upgrades, 6 milestones, 3 currencies): the per-frame tick costs about 9 µs, the screens' per-frame upkeep about 16 µs, a HUD rebuild about 90 µs and a full shop rebuild about 0.3 ms. Screens are rebuilt only when something they show changes, and idle income redraws at most 4 times a second.
Known limits
- Numbers are doubles: exact to 2^53, readable to about 1.8e308 (shown as ∞ beyond). No arbitrary-precision mode.
- Offline time is the wall clock between saves; a player who changes their device clock can move it.
- Bulk "max" and totals sum level by level (up to 100,000 levels per call), which keeps them exact for every curve.
- Editing
inc.modulewhile playing reloads it with no setup; leave and re-enter play after changing kit code. - The
kanjinumber style needs a font with CJK glyphs; the engine's bundled fonts have none.
Comments · 0
Open discussion, no rating attached. Ask questions, swap notes, follow threads.
Documented parts · 7
- incmodule
- IncHostcomponent
- incrementalKitpackage
- numbersmodule
- set-up-idle-ascentworkflow
- treemodule
- uimodule