Ask coding questions

← Back to all posts
Making A Simple Leveling System In Python
ClericDice (1)

My question is how you make a simple level system. Example is every win you get you get 10 XP. In order to level up you need to get 100 XP. Just wondering what’s the basic way of doing this.
A side question is how would you make a prestige system, every 10 levels you get a prestige?

Edit: Added the 'In Python' to the title.

Answered by SixBeeps (5331) [earned 5 cycles]
View Answer
Comments
hotnewtop
SixBeeps (5331)

A level system takes advantage of both variables and if statements. Declare XP, Level, and Prestige variables at the start:

xp = 0
player_level = 1
player_prestige = 0

Then in your main game code, update XP, then Level, then Prestige, accordingly. This is where the conditionals come into play:

...
if (player_has_won):
  print('you won!')

  # First, give the player XP
  xp += 10

  # If the player can level up, do so
  if (xp >= 100):
    level += 1
    xp = 0

    # If the new level is a multiple of 10 (every 10 levels...) award a prestige
    if (level % 10 == 0):
      prestige += 1
...