# Levels and experience system

I’m trying to make Runescape style skills (Yes, I know that’s pretty silly, it’s just a stupid thing for myself to do)

I have a massive table with the levels and experience, and I’m trying to check if there is enough experience to level up. So far I have this:

Every turn:
repeat with N running from 1 to the number of rows in the Table of Experience:
if the level in row N of the Table of Experience = melee level, and the exp in row N+1 of the Table of Experience <= melee experience:
now melee level is equal to the level in row N of the Table of Experience plus 1.

But it doesn’t like any of it.

Where are “melee level” and “melee experience” sourcing from? Are these properties of the player, or are they global variables?

Also, can you post the declaration, headers, and an example row or two from your table? (Use the code forum tag, that will make it easier to read.)

(I’ve made some assumptions based on what you posted.)

``````A person has a number called the melee level. The melee level is usually 1.
A person has a number called the melee experience. The melee experience is usually 0.

To gain is a verb.
To award (N - number) xp to (P - person):
if N <= 0, stop;
now the melee experience of P is the melee experience of P + N;
say "[The P] [gain] [N] experience. [The P] now [have] [the melee experience of P] experience."
[This might be a good place to check for a level gain instead of every turn.]

To award level (N - number) to (P - person):
if N <= the melee level of P, stop;
now the melee level of P is N;
say "[The P] [are] now level [N]!"

After jumping:
award 300 xp to the player.

After waving hands:
award 3000 xp to the player.

To check level increases for (P - person):
[Note that row 1 of the table corresponds to level 2, and so on.]
repeat with N running from the melee level of P to the number of rows in the Table of Experience:
choose row N in the Table of Experience;
if the melee experience of P < exp entry, break;
award level level entry to P.

Every turn:
repeat with P running through people:
check level increases for P.

Table of Experience
level		exp
2		1000
3		2000
4		4000

Training Room is a room.

[Restart in between these tests.]
Test small with "jump / g / g / g / g / g / g / g / g / g / g / g / g / g / g".
Test large with "wave / g / g".``````

For extra fun, try adding:

``Bob is a man in the Training Room.``

and giving him some xp also:

``````After jumping:
award 300 xp to the player;
award 500 xp to Bob.``````

You might want to add some “if the location of P is the location” tests if you don’t want the player to see announcements about NPCs that aren’t present (not an issue in this example, because there’s only one room).