MZ Making an EXP gauge with SRD's HUD Maker

Hi

I'm trying to make a simple EXP gauge with SRD's Hud Maker, where the gauge value is the amount of EXP and the max is how much EXP is needed to reach the next level, with the gauge resetting back to 0 each time the actor levels up. You know, like how you see in most RPGs. There doesn't seem to be an inbuilt way to achieve this (as far as I can tell).

I know it's possible, I've read old threads where people have worked it out:

But I haven't been able to replicate it, and I can't seem to work out it myself.

Based on their steps, I've tried:

Gauge Value
return ;$gameParty.members()[1].currentLevelExp()

Max Value
return ;$gameParty.members()[1].nextLevelExp()

The gauge shows up, but it stays empty.
I've also tried adding and removing return 0; at the start. Either it makes no difference, or I get an error.

Granted, the thread is 2019 and looks to be for MV, but it's the best I could find.

Anyone have a way I could do this?

Plugin:
return ;$gameParty.members()[1].currentLevelExp()
I've also tried adding and removing return 0; at the start.

did you try removing the semicolon entirely or putting it the end? sticking it directly in front of the return is going to make it return nothing.
Code:
return $gameParty.members()[1].currentLevelExp();
did you try removing the semicolon entirely or putting it the end? sticking it directly in front of the return is going to make it return nothing.
Code:
return $gameParty.members()[1].currentLevelExp();
I don't really know coding, so I just tested what different variations did, based on a code another user gave me a few days ago to get HP values.

I tried removing the semicolon entirely before, and I just tried putting it at the end now. Got the error message of:

TypeError
Cannot read property 'currentLevelExp' of undefined
ypeError
Cannot read property 'currentLevelExp' of undefined
thing to note - if youre trying to get the exp for the the first party member, you need $gameParty.members()[0], not 1. 1 would be the 2nd slot, and if there is no second actor you'd get that
thing to note - if youre trying to get the exp for the the first party member, you need $gameParty.members()[0], not 1. 1
So I changed the 1 to a 0 and it stops the message coming up.

But I've come across something odd. So my actor's class requires 50 EXP to get to level 2. When they enter the test map, I set an event to automatically give 25 EXP to that actor. Meaning the gauge should fill halfway. But nothing happens. Same when they defeat enemies and get EXP that way.

However, when they actually level up, either by battle or an event, then the gauge fills. But it's not reflecting their EXP between their current level and their next level. It just seems to show cumulative EXP, and the more they level up, the slower the gauge fills.

The thread I was looking at did mention something like that, so I went back and tried this code from the thread:

currentValue: return ${$gameParty.members()[0].currentExp() - $gameParty.members()[0].currentLevelExp()};
maxValue: return ${$gameParty.members()[0].nextLevelExp() - $gameParty.members()[0].currentLevelExp()};

When I tried it, the game didn't crash, but the gauge didn't display at all.
But I've come across something odd...
all currentLevelExp() does is fetch the amount of exp thats needed for an actor to get to their current level. i used it as the example because its something that you had already given. its doing exactly as it should.

currentValue: return ${$gameParty.members()[0].currentExp() - $gameParty.members()[0].currentLevelExp()};
maxValue: return ${$gameParty.members()[0].nextLevelExp() - $gameParty.members()[0].currentLevelExp()};
i dont think you should need the outer ${...} for either of those if what you had previously was working without them
all currentLevelExp() does is fetch the amount of exp thats needed for an actor to get to their current level. i used it as the example because its something that you had already given. its doing exactly as it should.


i dont think you should need the outer ${...} for either of those if what you had previously was working without them
Removed the ${...} and I think it's working now, thanks.
I'll keep testing it.
all currentLevelExp() does is fetch the amount of exp thats needed for an actor to get to their current level. i used it as the example because its something that you had already given. its doing exactly as it should.


i dont think you should need the outer ${...} for either of those if what you had previously was working without them
So it is working, but I'm now running into the same issue from before, which if I have a gauge set up for party member 3, and there isn't anyone in the 3 slot at that moment, I of course get the:

TypeError
Cannot read property 'currentExp' of undefined

message.
This is even if I put a condition in the gauge's display settings of checking if anyone is in party position 3 first.

Any way to get around that?
since youre in MZ, you should be able to use:
Code:
$gameParty.members()[0]?.currentExp() - $gameParty.members()[0]?.currentLevelExp()
and the same for the other. just place a question mark after the members()[x]wherever they show up
$gameParty.members()[0] can also be $gamePart.leader() as that = 0 (first member).

the ?. falls back to undefined and silence fail if undefined, as I like those shorthands
operator in JS what is possible.

Original thread: https://forums.rpgmakerweb.com/threads/making-an-exp-gauge-with-srds-hud-maker.183177/