Spielerando

Currency Wallet

A currency wallet holds the player's coins as whole numbers. Earning adds coins up to a limit, and the game is told what did not fit. Buying costs the full price or does not happen. Selling gives back only part of the price, so buying and selling in a loop never makes money.

Also called: Coin purse, Money system, Gold counter, Coin counter, Wallet.

A fox customer opens a coral-pink pouch so full of gold coins that some spill over the rim, while a badger merchant at a crate market stall holds out a glowing blue gem.
Pennywhistle Quay, an invented floating-island trading game. Invented game, image generated with AI.

Paste this to your AI

Copy it into Claude, Cursor or ChatGPT. It already has good values and the usual mistakes in it.

Add "Currency Wallet" to my game.

What it should do: A wallet turns effort into choices. The player earns coins, weighs what to buy, and feels the cost of each choice, so shops, rewards and prices all have a number to work with.

Build it exactly as this state machine. First check that it fits my game, then build it like this:

```mermaid
stateDiagram-v2
  [*] --> empty
  empty: Empty
  some: Some coins
  full: At the limit
  empty --> some: earns some coins
  empty --> full: earns a fortune
  some --> full: reaches the limit
  some --> empty: spends everything
  full --> some: spends some coins
  full --> empty: spends everything
```

Use these starting values:
- capacity: 9999 coins
- sellRatio: 0.5 share of price
- incomeBonus: 1 multiplier

Watch out for these common mistakes:
- Decimal prices leave dust: Tell your AI: keep all coins as whole numbers. Round a price up and a reward down, so the player never pays less or gets more than the number.
- Coins vanish at the limit: Tell your AI: take only what fits, report how much was left over, and let the game keep the rest of the bag where it lies.
- Buying and selling in a loop makes money: Tell your AI: selling gives back at most the price paid, rounded down, so every loop loses coins or breaks even.
- A negative price pays the player: Tell your AI: only spend when the price is a number above zero, and ignore anything else.
- A half payment goes through: Tell your AI: check the full price first. If the wallet cannot pay it, change nothing and say the purchase was refused.

Do not change anything else in the game. Do not claim anything without proof: model what it takes, and show me what your solution rests on and how I can see that it works. If you cannot show something, say you do not know. When you are done, tell me in plain words how to try it.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP

What it does

A wallet turns effort into choices. The player earns coins, weighs what to buy, and feels the cost of each choice, so shops, rewards and prices all have a number to work with.

How it runs, as a diagram

Everything it can be in, and what moves it on. Your AI builds from exactly this.

earns some coinsearns a fortunereaches the limitspends everythingspends some coinsspends everythingEmptySome coinsAt the limit
How it runs, as a diagram
  • Empty → Some coins: earns some coins
  • Empty → At the limit: earns a fortune
  • Some coins → At the limit: reaches the limit
  • Some coins → Empty: spends everything
  • At the limit → Some coins: spends some coins
  • At the limit → Empty: spends everything

Good starting values

ValueStart withWhat it changes
capacity9999 coinsThe most coins the wallet holds. A four-digit limit fits a counter on the screen and is far above what most shops ask. A lower limit makes players spend instead of hoarding.
sellRatio0.5 share of priceThe share of an item's price that selling gives back. Half makes a purchase a real commitment. It is never above one, because a higher share would pay the player to buy and sell in a loop.
incomeBonus1 multiplierA multiplier on coins earned, for events or upgrades. One means no bonus. It is never below one, because a bonus below one would quietly take coins away.

What usually goes wrong

Decimal prices leave dust

Prices and rewards with decimals, such as 0.1 and 0.2, do not add up exactly in a computer. The balance ends up a hair off, shows 9.999999 coins, or a price check says 'not enough' when the numbers look equal.

Fix: Tell your AI: keep all coins as whole numbers. Round a price up and a reward down, so the player never pays less or gets more than the number.

Coins vanish at the limit

The wallet is nearly full, the player picks up a bag of coins, and the whole bag disappears while only part fits. The player feels robbed.

Fix: Tell your AI: take only what fits, report how much was left over, and let the game keep the rest of the bag where it lies.

Buying and selling in a loop makes money

An item sells for as much as it costs, or a rounding step adds one coin, and the player buys and sells over and over until the shop is useless.

Fix: Tell your AI: selling gives back at most the price paid, rounded down, so every loop loses coins or breaks even.

A negative price pays the player

A broken shop entry, or a discount that overshoots, gives a price below zero. Spending it adds coins to the wallet instead of taking them.

Fix: Tell your AI: only spend when the price is a number above zero, and ignore anything else.

A half payment goes through

The player has 30 coins and an item costs 40. The shop takes the 30 and hands over the item, or leaves the wallet at minus 10.

Fix: Tell your AI: check the full price first. If the wallet cannot pay it, change nothing and say the purchase was refused.

How to check it works

Works well with

Common questions

how do i make a currency system in a game

Keep the coins as whole numbers in one balance. Earning adds up to a limit, buying takes the full price or does nothing, and selling gives back part of the price.

should game currency be whole numbers

Yes. Decimals do not add up exactly in a computer, so the balance drifts by tiny amounts. Whole numbers, with prices rounded up and rewards rounded down, stay exact.

how much should items sell for in a game shop

Start at half the buying price, rounded down. It makes buying a real choice and makes a buy and sell loop lose coins.

what do i tell my ai to add a coin wallet

Paste this: Add a coin wallet with whole numbers and a limit of 9999. Spending costs the full price or is refused. Earning takes only what fits and reports the rest. Selling gives back half the price, rounded down. Ignore amounts that are zero, negative or not numbers.

Where it comes from

We could not find a reliable origin for this one yet.

Where this mechanic comes from has not been researched yet.

Games are named only as references. Names and marks belong to their owners, and nothing here is endorsed by them.

What was checked

This is what separates the blueprint from a catalogue entry: the values on this page come from code that runs.

Your AI gets the code

Tested example code comes through the Spielerando connection, so your AI can use it right away. How to connect it