• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Carrying over EXP to next level?

O

Orvais

Guest
Just been following a simple youtube tutorial on an experience script for an rpg I'm trying to make.

I'm curious if there is a way to have the remaining experience I have left over carry over to the next level?

Here is my script.
Code:
//Create
t_level = 1;
t_exp = 0;
t_exptolevel = 60 * t_level

//Collission Event
with(other) {
    instance_destroy();
}

t_exp += 10;
if (t_exp > t_exptolevel) {
    t_level += 1;
    t_exp = 0;
    t_exptolevel = 60 * t_level
}
essentially when I collide with the object it gets destroyed and gives me 10 experience up to a max of 60 * the current level. What would I need to do to roll over remaining experience if I were to give it a higher number when I reach the max level up point?
 
Just store the difference between your t_exp and t_exptolevel since you already do a check to see if it's over, also, it's good to check if t_exp is ALSO equal to t_exptolevel.

For example:
Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   var leftover = t_exp - t_exptolevel;
   t_level += 1;
   t_exp = leftover;
   t_exptolevel = 60 * t_level
}
EDIT:
Looking at the code you don't even need to store it, just do the difference:

Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   t_level += 1;
   t_exp = t_exp - t_exptolevel;
   t_exptolevel = 60 * t_level
}
 
Last edited:
O

Orvais

Guest
Just store the difference between your t_exp and t_exptolevel since you already do a check to see if it's over, also, it's good to check if t_exp is ALSO equal to t_exptolevel.

For example:
Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   var leftover = t_exp - t_exptolevel;
   t_level += 1;
   t_exp = leftover;
   t_exptolevel = 60 * t_level
}
EDIT:
Looking at the code you don't even need to store it, just do the difference:

Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   t_level += 1;
   t_exp = t_exp - t_exptolevel;
   t_exptolevel = 60 * t_level
}
That did it! Thanks alot!
 
O

Orvais

Guest
Just store the difference between your t_exp and t_exptolevel since you already do a check to see if it's over, also, it's good to check if t_exp is ALSO equal to t_exptolevel.

For example:
Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   var leftover = t_exp - t_exptolevel;
   t_level += 1;
   t_exp = leftover;
   t_exptolevel = 60 * t_level
}
EDIT:
Looking at the code you don't even need to store it, just do the difference:

Code:
t_exp += 10;
if (t_exp >= t_exptolevel)
{
   t_level += 1;
   t_exp = t_exp - t_exptolevel;
   t_exptolevel = 60 * t_level
}
What if the experience I give my object overflows the next level? I tested it to see what would happen and it just kinda goes up by one instead like a few.

example:
Level: 1
Exp: 0 / 60

kill object, receive 500

Level: 2
Exp: 540/120. no idea why it givers me an extra 40 either.
 
What if the experience I give my object overflows the next level? I tested it to see what would happen and it just kinda goes up by one instead like a few.

example:
Level: 1
Exp: 0 / 60

kill object, receive 500

Level: 2
Exp: 540/120. no idea why it givers me an extra 40 either.
Then you would probably be better off using this code:
Code:
while(xp >= required)
{
level += 1;
xp -= required;
}
:)
 
Top