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

Get help using Construct 2

Post » Thu Jul 03, 2014 4:44 pm

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:
Image
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Thu Jul 03, 2014 5:07 pm

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
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Thu Jul 03, 2014 5:20 pm

I have tried that, and it seems the global number sum increases rapidly every tick.
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Thu Jul 03, 2014 5:31 pm

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
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Thu Jul 03, 2014 5:34 pm

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
B
92
S
32
G
109
Posts: 5,294
Reputation: 70,999

Post » Thu Jul 03, 2014 5:51 pm

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

Image
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Thu Jul 03, 2014 6:05 pm

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, .................]
Last edited by MrGoatsnake on Thu Jul 03, 2014 6:21 pm, edited 2 times in total.
B
21
S
5
G
1
Posts: 96
Reputation: 1,927

Post » Thu Jul 03, 2014 6:13 pm

@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.
Last edited by MrGoatsnake on Thu Jul 03, 2014 6:31 pm, edited 5 times in total.
B
21
S
5
G
1
Posts: 96
Reputation: 1,927

Post » Thu Jul 03, 2014 6:15 pm

Thanks guys!! I figured it out :)

Image
B
11
S
2
Posts: 91
Reputation: 1,017

Post » Thu Jul 03, 2014 6:20 pm

@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.
B
21
S
5
G
1
Posts: 96
Reputation: 1,927


Return to How do I....?

Who is online

Users browsing this forum: Artcadev, Google [Bot] and 46 guests