Hello, i'm trying to use a formula for experience needed to level up and wondering if this is possible to type in to set a value for every tick:

10 posts
• Page **1** of **1**

**Posts:**91**Reputation:**1,142

B

12
S

3
You'd have to reset sum to zero before every calculation. As a more complete example you could put it in a function so you could calculate xp() from anywhere with for example function.call("xp", 20).

global number sum=0

On function "xp"

---- set sum to 0

-------- for "n" from 1 to Function.param(0)-1

------------ add 75*2^(loopindex/7) to sum

-------- every tick

------------- function: set return to sum

global number sum=0

On function "xp"

---- set sum to 0

-------- for "n" from 1 to Function.param(0)-1

------------ add 75*2^(loopindex/7) to sum

-------- every tick

------------- function: set return to sum

**Posts:**5,521**Reputation:**84,005

B

98
S

36
G

132
Yes this is possible @Basilboy, if you understand that the formula is doing for you. That Riemann sum is for figuring out what the next XP level is for any given level number, from 0 to Max Level-1. Putting it in a loop will calculate every XP Boundary value when the loop is ran, this is not what you need. I think you just simply want to know the next level boundary at the time the level is increased. Here is loosely how you can use that:

Get yourself some global variables

CurrentLevel = 1

CurrentXP = 0

NextLevelAt = 75*2^(1/7) which is approx 82

Now set up an event

If CurrentXP > NextLevelAt its time to level up!

- Set CurrentLevel = CurrentLevel + 1

- Set NextLevelAt = NextLevelAt + (75*2^(CurrentLevel/7)

ORRRRRRRRRRRRRRRRRRRR!

You could just calculate out what all the level boundaries are by hand and hold them in C2 variables or array without using the formula in game.

Level 1 XP Boundary = 75*2^(1/7)

Level 2 XP Boundary = Level 1 XP Boundary + 75*2^(2/7)

Level 3 XP Boundary = Level 2 XP Boundary + 75*2^(3/7)

Level 4 XP Boundary = Level 3 XP Boundary + 75*2^(4/7)

[82, 173, 273, 384, .................]

Get yourself some global variables

CurrentLevel = 1

CurrentXP = 0

NextLevelAt = 75*2^(1/7) which is approx 82

Now set up an event

If CurrentXP > NextLevelAt its time to level up!

- Set CurrentLevel = CurrentLevel + 1

- Set NextLevelAt = NextLevelAt + (75*2^(CurrentLevel/7)

ORRRRRRRRRRRRRRRRRRRR!

You could just calculate out what all the level boundaries are by hand and hold them in C2 variables or array without using the formula in game.

Level 1 XP Boundary = 75*2^(1/7)

Level 2 XP Boundary = Level 1 XP Boundary + 75*2^(2/7)

Level 3 XP Boundary = Level 2 XP Boundary + 75*2^(3/7)

Level 4 XP Boundary = Level 3 XP Boundary + 75*2^(4/7)

[82, 173, 273, 384, .................]

Last edited by MrGoatsnake on Thu Jul 03, 2014 6:21 pm, edited 2 times in total.

**Posts:**96**Reputation:**1,937

B

21
S

5
G

1
@R0J0hound 's solution technically works but if you are using this as a part of a level system that would constantly be calling xp(), I would recommend doing it more like my explanation, that way the function with all the looping doesn't get called too much adding unneeded complexity.

As you can see Riemann sums are calculated by adding the result of one formula calculation with the result of the next and so on. If you look at my example, I calculate the first boundary, store it, and then calculate the next boundary by adding what I already have to the next calculation and so on. In my solution the next bit of the formula only gets called when you need it. In @R0J0hound 's solution, it will calculate all the intermediate xp boundaries until it gets to the one you need, which is a waste of processing.

As you can see Riemann sums are calculated by adding the result of one formula calculation with the result of the next and so on. If you look at my example, I calculate the first boundary, store it, and then calculate the next boundary by adding what I already have to the next calculation and so on. In my solution the next bit of the formula only gets called when you need it. In @R0J0hound 's solution, it will calculate all the intermediate xp boundaries until it gets to the one you need, which is a waste of processing.

Last edited by MrGoatsnake on Thu Jul 03, 2014 6:31 pm, edited 5 times in total.

**Posts:**96**Reputation:**1,937

B

21
S

5
G

1
@Basilboy I would still recommend not using the XP function every tick because you are making it loop over and over calculating things you really don't need. Breaking the Riemann sum up, storing its intermediate calculations, and only adding what you need when you need it will speed all this up.

**Posts:**96**Reputation:**1,937

B

21
S

5
G

1
10 posts
• Page **1** of **1**

## Who is online |

Users browsing this forum: No registered users and 33 guests |