Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Yes Im spamming this place, another question - variable math

Hello,
For my system you get xp when you catch a fish, stored in an event variable. But, with this scene and a window, I show the lvls you have now. But the point is, as with every salmon you fish you get a random between 4 and 6 xp, you get after a while an insane ammount of exp... How can you make a formula to change the xp to a level?
Thanks!
~Smiff
 

e

Sponsor

What you could do is use the current leveling up system. That is, you just give XP to a character and the current system will level him/her up for you. Basically, you take your Game_Actor object and you do:

Code:
$game_party.actors[$game_player.id].exp += 1

Where 1 is the XP (so change that to whatever your formula is).

The Game_Actor#exp= method will take care of level-upping the player.

The above code would change the $game_player (the visible character on the map) xp.
 

Tdata

Sponsor

Why not do something along the lines of:

Code:
base_exp * (level +1) + rand(-10...10)
If base_exp is 50 and the next level is 3 then you would need 190-210 exp to level up to level 4...
 
Well, what I want to do is fairly simple I believe, but cant figure it out. In the event system, you fish fish (duhh) and if you catch something, you get xp counted in a variable. I also scripted a window showing the current level, just like the levels in other skills. But the point is, if you catch a fish, you get at least 1xp, because thats the lowest. Its a bit high, because you dont level every time you catch a fish >.<. So, I want to make a formula like fishing_xp*0.5 = fishing_level. Its not exactly this but if I know how I can play around with it.
 
typically, this is done with a curve rather than linear. The reason being that your success should improve as you advance levels. so you want it more difficult to get from level 49 to 50 than it is to get from level 4 to 5.

You probably want to use an exponential curve, for example:

Code:
LVL = SQRT(EXP)

EXP          LVL
1             1
4             2
9             3
100         10
10000      100

to do this using the script event command, assume your EXP is variable 1, and you want to store the Level in variable 2

Code:
$game_variables[2] = Math.sqrt($game_variables[1])

The problem, this won't fit in the event command editor, so you have to split it up.
Use the \ character to continue a line. Make sure there is no space after the \

$game_variables[2] = \
Math.sqrt($game_variables[1])
 
THANKS! That is nice! Gonna try that out ;)
EDIT: Works exactly as I wanted, but it now shows as for example 3.482884884, how can I make it just 3? Also, 3/985773 should also be 3.
And another thing I want to try, is make a list with the exp needed for every level, so that I already have that and can do some more funny things with it. Like how many xp for next level.

EDIT2: I just tested some more, and it is a bit strange, if you have:
0xp = lvl 0
1xp = lvl 1
2xp = lvl 1.4
3xp = lvl 1.7
4xp = lvl 2
5xp = lvl 2.2
6xp = lvl 2.4
7xp = lvl 2.6
8xp = lvl 2.8
9xp = lvl 3

You'd pretty lvl very fast, assuming you gain at least 1 xp every fish you catch. So I added a * 0.1 after it, giving:
0xp = lvl 0
1xp = lvl 0.1
2xp = lvl 0.14
3xp = lvl 0.17
100xp = lvl 1
400xp = lvl 2

Which is pretty slow, you see that gaining just level 2 requires 4 times!! the xp for level 1. If you want to become level 3, you need 900xp, which is 2.25 times the xp of the previous level. This is a bit too much I think, so I didnt do it * 0.1 but * 0.3. That would give the following numbers:
1xp = lvl 0.3
100xp = lvl 3
400xp = lvl 6
900xp = lvl 9

For what shall I go? A formula behind it, or just a library of numbers I made before and set in the script?
 
It's up to you which to use. I prefer a formula since any curve can be represented by a formula, and it saves building an array, hash, or table.

You can use the method .to_int on an object to convert it to an integer.

$game_variables[2] = Math.sqrt($game_variables[1]).to_int

or

$game_variables[2] = (Math.sqrt($game_variables[1]) * 0.3).to_int
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top