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.

[VX] Resetting EXP to 0

Jason

Awesome Bro

Hi,

So I've finished adding HP/MP/EXP bars into my HUD, however, I have a problem, the EXP bar, after levelling up, doesn't go back to 0, and I THINK I know why;

Say at level 1, you need 10 EXP to level up, then at level 2 you need 30 EXP to level up,
The EXP Bar works throughout level 1, going up by the right amount, but when it gets to level 2, the bar sets itself 1/3 of the way into the bar (Hard to understand ?)

When I go into Status, I see it says I have 10 EXP, and need 30 EXP to level, so what the bar is showing me, is how much EXP I have, out of how much I need to level (10/30, 1/3 of the bar as said.)

Here's the code for the EXP bar;
Code:
 

  def draw_expbar(actor, x, y)

    back = Cache.system(Base)

    cw = back.width

    ch = back.height

    src_rect = Rect.new(0, 0, cw, ch)

    self.contents.blt(x, y, back, src_rect)

    return if actor.exp_s <= 0

    meter = Cache.system(EXP_Bar)

    cw = meter.width * actor.exp_s / actor.next_rest_exp_s

    ch = meter.height

    src_rect = Rect.new(0, 0, cw, ch)

    self.contents.blt(x, y, meter, src_rect)

  end

 

If it can't be fixed, is there a way I can make it so once I level up, the current EXP is reset to 0 ? (Much like World of Warcraft, when you level up, your EXP goes back to 0),

Thanks.
 

Jason

Awesome Bro

Hmm and where would I do that ? Do I replace

Code:
 

cw = meter.width * actor.exp_s / actor.next_rest_exp_s

 

Cause I'm pretty new to RGSS2 and don't know all the Syntax' lol.
 
Why not just create a new method in Game_Actor to return the current level exp...

class Game_Actor
def curr_exp_s
return @exp_list[@level] > 0 ? @exp_list[@level] : "-------"
end
end

Then use:

cw = meter.width * (actor.exp - actor.curr_exp_s) / (actor.next_exp_s - actor.curr_exp_s)
 

Jason

Awesome Bro

Okay now for some reason my game has completely fucked up,

I added the new method, and changed my cw code to yours, and then I got multiple errors, managed to fix them, and now I get an error with Game_Character, on line 235, even if I make a new game and paste the scripts I'm using in (So Game_Actor hasn't got the extra code)

The error says;
undefined method `[]' for nil:NilClass

And no matter what I do or change, that error pops up EVERY TIME.

Any ideas ?
 

Jason

Awesome Bro

Bump.

Brew, the thing you told me to do kinda fucked up my game, and whenever I paste the scripts into a new game I keep getting the same error on line 235 of Game_Character, which is;

Code:
 

    return (@tile_id > 0 or @character_name[0, 1] == '!')

 

Any ideas ?
 
Ok, if you paste your scripts into a new game, without my method, then my method is not the problem.

Also, you said you fixed multiple errors, but didn't paste the fixed line that assigns cw.

This works (I tested it):
Code:
    actor = $game_actors[1]

    zoom = (actor.exp - actor.curr_exp_s.to_f) / (actor.next_exp_s.to_f - actor.curr_exp_s.to_f)

    self.zoom_x = zoom

it calculates the zoom factor for the bar between 0 & 1, so it can be used as the zoom_x property of the bitmap.
I initialized the zoom factor to 0, and as EXP is gained, it increases approaching 1 (100%).
When the player levels up, the ratio gets set back to 0.
 

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