Wrong calculations?
#1

I have an XP system, and I'm using an exponential growth formula to calculate xp required for each level, but it doesn't seem to have the right values, it goes up by one, and then goes up a big amount every so often, instead of increasing gradually like it's suppose to...
Heres the results of the xp needed for the first two ranks:
Quote:

[21:06:55] 0: 400
[21:06:55] 1: 401
[21:06:55] 2: 402
[21:06:55] 3: 403
[21:06:55] 4: 404
[21:06:55] 5: 405
[21:06:55] 6: 406
[21:06:55] 7: 807
[21:06:55] 8: 808
[21:06:55] 9: 809
[21:06:55] 10: 810
[21:06:55] 11: 811
[21:06:55] 12: 812
[21:06:55] 13: 813
[21:06:55] 14: 1614
[21:06:55] 15: 1615
[21:06:55] 16: 1616
[21:06:55] 17: 1617
[21:06:55] 18: 1618
[21:06:55] 19: 1619
[21:06:55] 20: 1620
[21:06:55] 21: 3221
[21:06:55] 22: 3222
[21:06:55] 23: 3223
[21:06:55] 24: 3224
[21:06:55] 25: 3225
[21:06:55] 26: 3226
[21:06:55] 27: 3227

And here is the function to get points needed for a specific rank...
Код:
GET_RANK_POINTS(rank) {
	new points;
  	points = rank/7;
	new Float:floatpoints = floatpower(2,points);
 	points = rank+400*floatround(floatpoints);
	return points;
}
I'm pretty sure the calculation is correct? Is it pawn being weird? How can I fix this?
Reply
#2

pawn Код:
points = rank/7;
An integer divided by an integer results in an integer. The fractional part (anything behind the dot) of the division is simply dropped, no rounding occurs. For example, 6/7 is 0.857... but since the fractional part is dropped, 0 is returned. If you need the fractional part you need to make that variable a float.
Reply
#3

this is my new formula, after changing stuff to floats...
Quote:

forward Float:GET_RANK_POINTS(Float:rank);
stock Float:GET_RANK_POINTS(Float:rank) {
new Floatoints;
points = rank/7.0;
new Float:floatpoints = floatpower(2.0,points);
points = rank+400.0*floatround(floatpoints);
return points;
}

and this is my test command code to get xp for all ranks...

Quote:

for(new i = 0; i <= 100; i++) {
printf("%f: %f",Float:i,GET_RANK_POINTS(i));
}

and these are my new xp results from test.. (top couple again)...

the results are a bit more normal now (not the first few, they still weird, but some of the higher xp is more normal, and growing nicely), but still getting lots of 0000's after the result... and the index of loop is just returning 0.0000. Why is this :O? And thanks for the help btw, +rep !

Quote:

[21:46:13] 0.000000: 400.000000
[21:46:13] 0.000000: 401.000000
[21:46:13] 0.000000: 402.000000
[21:46:13] 0.000000: 403.000000
[21:46:13] 0.000000: 404.000000
[21:46:13] 0.000000: 805.000000
[21:46:13] 0.000000: 806.000000
[21:46:13] 0.000000: 807.000000
[21:46:13] 0.000000: 808.000000
[21:46:13] 0.000000: 809.000000
[21:46:13] 0.000000: 1210.000000
[21:46:13] 0.000000: 1211.000000
[21:46:13] 0.000000: 1212.000000
[21:46:13] 0.000000: 1613.000000
[21:46:13] 0.000000: 1614.000000
[21:46:13] 0.000000: 1615.000000
[21:46:13] 0.000000: 2016.000000
[21:46:13] 0.000000: 2017.000000
[21:46:13] 0.000000: 2418.000000
[21:46:13] 0.000000: 2819.000000
[21:46:13] 0.000000: 2820.000000
[21:46:13] 0.000000: 3221.000000
[21:46:13] 0.000000: 3622.000000
[21:46:13] 0.000000: 4023.000000
[21:46:13] 0.000000: 4424.000000

xp is still a bit odd, not really going up gradually, it's going up in big jumps.


###########################################
EDIT:

Silly me, left the floatround() function in, removed that and it works like a charm! Thanks again vince!
Reply
#4

Quote:
Originally Posted by wooolly
Посмотреть сообщение
..., but still getting lots of 0000's after the result... and the index of loop is just returning 0.0000. Why is this :O? And thanks for the help btw, +rep !
The fractional part will always be zero because you round the float value (the others a both integer)
The index is always 0.0 because you didn't use a float number

Quote:
Originally Posted by wooolly
Посмотреть сообщение
xp is still a bit odd, not really going up gradually, it's going up in big jumps.
Because of the rounding , also do you want a line or an exponential like it already is ?

Just try it without it
pawn Код:
stock Float: GET_RANK_POINTS(rank) {
    return rank + 400.0 * floatpower(2.0, rank / 7.0); // rank + 400.0 * floatpower(1.1041, rank)
}
pawn Код:
for(new i = 0; i <= 100; i++) {
    printf("%d: %f", i, GET_RANK_POINTS(i));
}
You could leave the rank + at the end away because it gets negligible small
Reply
#5

Thanks for the help got it working now, the 400.0*floatround(floatpoints); was messing it up, i forgot to delete it, it's exponential now yay +1 rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)