Spielerando

Experience and Levels

Experience and levels turn everything a player does into steady growth. Actions earn points, and the total decides the level. Each level costs more than the one before, leftover points carry over, and one big reward can lift the player several levels. At the top level the bar simply stays full.

Also called: XP system, Leveling, Experience points, Level-up system.

A young hedgehog apprentice with raised fists is lifted by three golden rings of light in a tall spiral, while a glass gauge beside her overflows into the next tube.
Brambleclimb Academy, an invented comic-style fantasy adventure. 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 "Experience and Levels" to my game.

What it should do: Levels give the player a clear sense of getting stronger and a next goal that is always close. Rising costs keep the early levels quick and the later ones a real achievement.

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

```mermaid
stateDiagram-v2
  [*] --> fresh
  fresh: No points yet
  climbing: Earning points
  levelup: Just levelled up
  maxed: Top level
  fresh --> fresh: nothing earned
  fresh --> climbing: earns points
  fresh --> levelup: earns enough
  fresh --> maxed: earns a huge gain
  climbing --> climbing: earns points
  climbing --> levelup: crosses a level line
  climbing --> maxed: reaches the top
  levelup --> climbing: earns a bit more
  levelup --> levelup: levels up again
  levelup --> maxed: reaches the top
  maxed --> maxed: points are dropped
  maxed --> [*]
```

Use these starting values:
- baseXp: 100 points
- growth: 1.4
- maxLevel: 30

Watch out for these common mistakes:
- A big reward gives only one level: Tell your AI: after a gain, keep levelling up until the points no longer reach the next level.
- Leftover points vanish on a level-up: Tell your AI: store the total, and work out the progress inside a level by subtracting the level line.
- The level and the points disagree: Tell your AI: save only the total points, and work out the level from it every time.
- Past the top level: Tell your AI: stop the total at the points the top level needs, and show a full bar there.
- A penalty or a bad number ruins the total: Tell your AI: count a gain below zero or not a number as zero. If a penalty should exist, take points off the bar inside the current level and never below its line.
- A level that costs nothing: Tell your AI: round each cost to a whole number and make it at least 1.

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

Levels give the player a clear sense of getting stronger and a next goal that is always close. Rising costs keep the early levels quick and the later ones a real achievement.

How it runs, as a diagram

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

nothing earnedearns pointsearns enoughearns a huge gainearns pointscrosses a level linereaches the topearns a bit morelevels up againreaches the toppoints are droppedNo points yetEarning pointsJust levelled upTop level
How it runs, as a diagram
  • No points yet → No points yet: nothing earned
  • No points yet → Earning points: earns points
  • No points yet → Just levelled up: earns enough
  • No points yet → Top level: earns a huge gain
  • Earning points → Earning points: earns points
  • Earning points → Just levelled up: crosses a level line
  • Earning points → Top level: reaches the top
  • Just levelled up → Earning points: earns a bit more
  • Just levelled up → Just levelled up: levels up again
  • Just levelled up → Top level: reaches the top
  • Top level → Top level: points are dropped

Good starting values

ValueStart withWhat it changes
baseXp100 pointsWhat the first level costs, and the scale for all the others. At 100, a player who earns 10 points per fight reaches level 2 after ten fights.
growth1.4How fast the cost of a level grows. At 1.4, going from level 10 to 11 costs about 25 times the first level. At 1 the cost grows in even steps, and at 3 the late levels become huge.
maxLevel30The top level. At the starting values it takes 140372 points to reach level 30. Points beyond that are dropped, because a bar that never fills would suggest more to come.

What usually goes wrong

A big reward gives only one level

The code checks for a level-up once per gain. A boss that gives 835 points leaves the player at level 2, and each following fight gives one more level until it catches up.

Fix: Tell your AI: after a gain, keep levelling up until the points no longer reach the next level.

Leftover points vanish on a level-up

The bar is emptied to zero on every level-up. A player who gets 130 points when 100 were needed loses the extra 30, and feels the game is stealing from them.

Fix: Tell your AI: store the total, and work out the progress inside a level by subtracting the level line.

The level and the points disagree

The level and the points are saved as two separate numbers. A bug, an edit or an old save leaves them out of step, and a player with 5000 points is shown as level 1.

Fix: Tell your AI: save only the total points, and work out the level from it every time.

Past the top level

Nothing stops the points at the top. The player becomes level 31 in a game that has 30, the table of level lines is read past its end, and the game crashes or shows nonsense.

Fix: Tell your AI: stop the total at the points the top level needs, and show a full bar there.

A penalty or a bad number ruins the total

A death penalty adds minus 50, or a bonus formula returns a value that is not a number. The level drops, or the total turns into a value that is not a number and the player is stuck for good.

Fix: Tell your AI: count a gain below zero or not a number as zero. If a penalty should exist, take points off the bar inside the current level and never below its line.

A level that costs nothing

A tiny base cost rounds to zero for a level. Two levels sit on the same line, and one gain skips straight past a level without its reward.

Fix: Tell your AI: round each cost to a whole number and make it at least 1.

How to check it works

Works well with

Common questions

how do experience and levels work in games

Actions earn points and the points add up to a total. The total decides the level, using a table of lines. Each level needs more points than the last, and extra points carry over into the next level.

how much xp should each level need

Start with the first level costing about 10 actions' worth of points, and let each level cost somewhat more. A growth of 1.4 makes level 10 cost about 25 times the first. Test by playing: no level should take much longer than the one before feels fair.

should dying cost experience

Be careful. Losing levels hurts a lot and can make players quit. A softer choice is to lose points inside the current level only, never below its line, so the level is always kept.

what do i tell my ai to add experience and levels

Paste this: Add experience points. Save only the total. Going from level n to n+1 costs 100 times n to the power 1.4, rounded. Work out the level from the total each time, carry leftover points over, allow several level-ups at once, and stop at level 30.

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