• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Real/Integer limit....?

Status
Not open for further replies.
Level 12
Joined
May 4, 2008
Messages
1,111
im coding a EXP curve based on a real game's EXP Curve (for purpose of making it as close as possible gameplay-wise) whenever i reach 520K total XP, the Real spikes to negative values.... is that supposed to happen? posing a small log of the level-up process


00:00:00.13 Need: 616
00:00:00.13 Running gt_Init_Func (Event: Timer (0.1, Periodic: 0))
00:00:05.00 Need: 949
00:00:05.00 Lvl: 7
00:00:05.00 Need: 1385
00:00:05.00 Lvl: 8
00:00:05.00 Need: 1935
00:00:05.00 Lvl: 9
00:00:05.00 Need: 2615
00:00:05.00 Lvl: 10
00:00:05.00 Need: 3438
00:00:05.00 Lvl: 11
00:00:05.00 Need: 4461
00:00:05.00 Lvl: 12
00:00:05.00 Need: 5661
00:00:05.00 Lvl: 13
00:00:05.00 Need: 7052
00:00:05.00 Lvl: 14
00:00:05.00 Need: 8650
00:00:05.00 Lvl: 15
00:00:05.00 Need: 10467
00:00:05.00 Lvl: 16
00:00:05.00 Need: 12519
00:00:05.00 Lvl: 17
00:00:05.00 Need: 14820
00:00:05.00 Lvl: 18
00:00:05.00 Need: 17383
00:00:05.00 Lvl: 19
00:00:05.00 Need: 20223
00:00:05.00 Lvl: 20
00:00:05.00 Need: 23354
00:00:05.00 Lvl: 21
00:00:05.00 Need: 26887
00:00:05.00 Lvl: 22
00:00:05.00 Need: 30749
00:00:05.00 Lvl: 23
00:00:05.00 Need: 34953
00:00:05.00 Lvl: 24
00:00:05.00 Need: 39516
00:00:05.00 Lvl: 25
00:00:05.00 Need: 44451
00:00:05.00 Lvl: 26
00:00:05.00 Need: 49772
00:00:05.00 Lvl: 27
00:00:05.00 Need: 55496
00:00:05.00 Lvl: 28
00:00:05.00 Need: 61635
00:00:05.00 Lvl: 29
00:00:05.00 Need: 68205
00:00:05.00 Lvl: 30
00:00:05.00 Need: 75220
00:00:05.00 Lvl: 31
00:00:05.00 Need: 82798
00:00:05.00 Lvl: 32
00:00:05.00 Need: 90856
00:00:05.00 Lvl: 33
00:00:05.00 Need: 99411
00:00:05.00 Lvl: 34
00:00:05.00 Need: 108476
00:00:05.00 Lvl: 35
00:00:05.00 Need: 118066
00:00:05.00 Lvl: 36
00:00:05.00 Need: 128197
00:00:05.00 Lvl: 37
00:00:05.00 Need: 138882
00:00:05.00 Lvl: 38
00:00:05.00 Need: 150138
00:00:05.00 Lvl: 39
00:00:05.00 Need: 161978
00:00:05.00 Lvl: 40
00:00:05.00 Need: 174417
00:00:05.00 Lvl: 41
00:00:05.00 Need: 187471
00:00:05.00 Lvl: 42
00:00:05.00 Need: 201153
00:00:05.00 Lvl: 43
00:00:05.00 Need: 215480
00:00:05.00 Lvl: 44
00:00:05.00 Need: 230465
00:00:05.00 Lvl: 45
00:00:05.00 Need: 246123
00:00:05.00 Lvl: 46
00:00:05.00 Need: 262470
00:00:05.00 Lvl: 47
00:00:05.00 Need: 279519
00:00:05.00 Lvl: 48
00:00:05.00 Need: 297287
00:00:05.00 Lvl: 49
00:00:05.00 Need: 315787
00:00:05.00 Lvl: 50
00:00:05.00 Need: 335034
00:00:05.00 Lvl: 51
00:00:05.00 Need: 355044
00:00:05.00 Lvl: 52
00:00:05.00 Need: 375830
00:00:05.00 Lvl: 53
00:00:05.00 Need: 397409
00:00:05.00 Lvl: 54
00:00:05.00 Need: 419794
00:00:05.00 Lvl: 55
00:00:05.00 Need: 443000
00:00:05.00 Lvl: 56
00:00:05.00 Need: 467043
00:00:05.00 Lvl: 57
00:00:05.00 Need: 491936
00:00:05.00 Lvl: 58
00:00:05.00 Need: 517696
00:00:05.00 Lvl: 59
00:00:05.00 Need: -504240
00:00:05.00 Lvl: 60
00:00:05.00 Need: -476705
00:00:05.00 Lvl: 61
00:00:05.00 Need: -447875
00:00:05.00 Lvl: 62
00:00:05.00 Need: -418108
00:00:05.00 Lvl: 63
00:00:05.00 Need: -387388
00:00:05.00 Lvl: 64
00:00:05.00 Need: -355700
00:00:05.00 Lvl: 65
00:00:05.00 Need: -323030
00:00:05.00 Lvl: 66
00:00:05.00 Need: -289363
00:00:05.00 Lvl: 67
00:00:05.00 Need: -254683
00:00:05.00 Lvl: 68
00:00:05.00 Need: -218975
00:00:05.00 Lvl: 69
00:00:05.00 Need: -182225
00:00:05.00 Lvl: 70
00:00:05.00 Need: -144418
00:00:05.00 Lvl: 71
00:00:05.00 Need: -105538
00:00:05.00 Lvl: 72
00:00:05.00 Need: -65570
00:00:05.00 Lvl: 73
00:00:05.00 Need: -24500
00:00:05.00 Lvl: 74
00:00:05.00 Need: 17687
00:00:05.00 Lvl: 75
00:00:05.00 Need: 61007
00:00:05.00 Lvl: 76
00:00:05.00 Need: 105475
00:00:05.00 Lvl: 77
00:00:05.00 Need: 151105
00:00:05.00 Lvl: 78
00:00:05.00 Need: 197912
00:00:05.00 Lvl: 79
00:00:05.00 Need: 245912
00:00:05.00 Lvl: 80
00:00:05.00 Need: 295120
00:00:05.00 Lvl: 81
00:00:05.00 Need: 346895
00:00:05.00 Lvl: 82
00:00:05.00 Need: 399940
00:00:05.00 Lvl: 83
00:00:05.00 Need: 454271
00:00:05.00 Lvl: 84
00:00:05.00 Need: 509904
00:00:05.00 Lvl: 85
00:00:05.00 Need: -481723
00:00:05.00 Lvl: 86
00:00:05.00 Need: -423442
00:00:05.00 Lvl: 87
00:00:05.00 Need: -363813
00:00:05.00 Lvl: 88
00:00:05.00 Need: -302822
00:00:05.00 Lvl: 89
00:00:05.00 Need: -240452
00:00:05.00 Lvl: 90
00:00:05.00 Need: -176688
00:00:05.00 Lvl: 91
00:00:05.00 Need: -111515
00:00:05.00 Lvl: 92
00:00:05.00 Need: -44918
00:00:05.00 Lvl: 93
00:00:05.00 Need: 23119
00:00:05.00 Lvl: 94
00:00:05.00 Need: 92612
00:00:05.00 Lvl: 95
00:00:05.00 Need: 163575
00:00:05.00 Lvl: 96
00:00:05.00 Need: 236024
00:00:05.00 Lvl: 97
00:00:05.00 Need: 309975
00:00:05.00 Lvl: 98
00:00:05.00 Need: 385443
00:00:05.00 Lvl: 99


  • General - If (Conditions) then do multiple (Actions)
    • If Then Else
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 2.0
              • Lvl <= 11.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[1] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 12.0
              • Lvl <= 21.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[2] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 22.0
              • Lvl <= 31.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[3] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 32.0
              • Lvl <= 41.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[4] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 42.0
              • Lvl <= 51.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[5] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 52.0
              • Lvl <= 61.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[6] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 62.0
              • Lvl <= 81.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[7] * ((Lvl ^ 2.0) / 10.0)))
      • General - Else if (Conditions) then do (Actions)
        • Else If
          • And
            • Conditions
              • Lvl >= 82.0
              • Lvl <= 99.0
        • Then
          • Variable - Set Total XP = (Total XP + (EXP MOD[8] * ((Lvl ^ 2.0) / 10.0)))
thats the level-up curve

if anyone can provide a fix or a way to fix it, im all ears :D
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
I would only assume that Total XP is of a fixed type (real), because an integer has a much more allowed value than this.

It turns out the maximum value of a real/fixed is 524288 and the minimum is -524288
to be precise, the max value is 2^19 and the min value -2^19

The easiest workaround is to actually have Total XP as a integer type instead. At such high values the precision of decimal points for a real will be truncated anyway, and it should not be a problem to round up to closest integer value.

It will first be when you get a value which is higher than 2^31-1 that the int will start of from it's minimum value -2^31
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
oh, if you want a tip from me by the way, I would really ditch those if else if else stuff, as you can narrow all that down to just a few lines if you make preset array variables instead.
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Sure, I was not talking about speed optimization, I was more thinking about code optimization to narrow the script's filesize down. And it would increase readability (maybe not, but I think it looks better and more practical) :)

However, I would like to point out, that since you now are using if/then/else-if/then[...] you don't need to check the lowest bounds of the level.

say you are lvl 30, it is enough to first check if it is <=11, if it is not, then check if it is <= 21, and finally if it is <= 31.

Also, even better, you don't even have to make any presets for this code in general. Since it is such a basic algoritm, all this could be narrowed down to only one line of code:
  • Set Total XP = (Total XP + (EXP MOD[(Lvl - 2) / 10 + 1] * ((Lvl ^ 2.0) / 10.0)))
That's all it takes :)
 
Level 23
Joined
Nov 29, 2006
Messages
2,482
Maybe you misunderstood what that code does. The (Lvl - 2) / 10 + 1 part just finds the right index for you in the MOD array, so simply, MOD is still determined right by the level.

And yeah you do as you wish ofcourse:>
 
Level 12
Joined
May 4, 2008
Messages
1,111
but... what do u do with these:
2-11
12-21
22-31
32-41
42-51
52-61
62-81<<<<<
82-99<<<<< 20-level increment, yours would probbly only take in account a 10-level increment as far as i see :p
 
Level 12
Joined
May 4, 2008
Messages
1,111
^_^ but u like rly saved my life with that interger code XD cuz then in-game the character wouldve have leveled up 25 times in a row, then after 3 battles wouldve leveled to 99 XD going from 50 to 99 in 3 fights... not a good idea XD
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,199
Fixedpoint uses simlar techniques to integers when being manipulated (addition is exactly the same as normal integer addition). As such you may wish to see if you can cut fixedpoint out of the equation alltogether and just use integers (with the right divisors). I believe this is what square enix used in their FF games to calculate EXP.

Also you can remove the multiple selection by using a formula to generate the right modifier index from the level. Although this may use a few more modifer indicies, it will save on execution time as it no longer will have to check multiple ranges.
 
Level 5
Joined
Jul 10, 2010
Messages
124
you could also reduce the exp curve by a factor that lets your max level be under the limit, and then reduce the exp gain from kills by the same factor. but this is a last resort
 
Level 12
Joined
May 4, 2008
Messages
1,111
Fixedpoint uses simlar techniques to integers when being manipulated (addition is exactly the same as normal integer addition). As such you may wish to see if you can cut fixedpoint out of the equation alltogether and just use integers (with the right divisors). I believe this is what square enix used in their FF games to calculate EXP.

Also you can remove the multiple selection by using a formula to generate the right modifier index from the level. Although this may use a few more modifer indicies, it will save on execution time as it no longer will have to check multiple ranges.

just realise last said idea (4 posts ago) would work if i added 3 mroe indexes and yeah it would save up some calc :D thanks
 
Status
Not open for further replies.
Top