0 Favourites

How do I enter this formula? Is it even possible?

  • 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:

  • You'll have to do it with a loop. Something like this:

    global number sum=0

    for "n" from 1 to L-1

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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • I have tried that, and it seems the global number sum increases rapidly every tick.

  • But I may have not done what you said correctly...

    I created a global variable called sum with an inital value of 0

    and did

    for "n" from 1 to Player.Level-1

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

    The Player.Level being an instance variable equal to 1

  • 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

  • would it be like this? Not sure how it works but

  • 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, .................]

  • 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.

  • Thanks guys!! I figured it out

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)