[RMMV] Display CurrentEXP / ToNextLevelEXP?

I am using SRD_MenuStatusCustomizer to make my menu screen more compact but filled with more information.

There is an option to show the exp bar which I love because then I could remove the status menu option, which is then obsolete.
However, said EXP bar does not tell you concrete numbers but rather is just a gauge that fills up as you gain EXP.

So my question is;
is there an Eval to display an actors current EXP and/or required EXP for the next level (preferably the latter)


I'd like it to look like this:
Next Level: X EXP
Try

"Next Level: " + actor.nextRequiredExp()
Hey, that worked like a charm! Thank you, Trihan!

Edit: @Trihan Ehh one more little thing;
The EXP required shows up even at maximum level.
So right now it shows that the character needs 81099 EXP to level up even though they are at max level.
An if-statement is probably required to check if the character is maxlevel. If they are, the number of EXP should be replaced by "---" or anything else but a number basically.
I think you can use "actor.isMaxLevel()" in a conditional to do what you described.
Yeah, I did find that function you mentioned and I tried something similar to what you suggested, but I couldn't really get it to work.

This is what it looks like right now:

Eval: "Next Level: " + actor.nextRequiredExp() + " EXP"
This works just fine, but has the problem I mentioned before.

However, I can't seem to make an If-statement work in the middle part. It always shows no text at all (because there was some kind of error most likely).
And it certainly does not help that I am not particularly familiar with JS syntax.
Yeah, I did find that function you mentioned and I tried something similar to what you suggested, but I couldn't really get it to work.

This is what it looks like right now:

Eval: "Next Level: " + actor.nextRequiredExp() + " EXP"
This works just fine, but has the problem I mentioned before.
What did you try? I think, off the top of my head, this ought to work...
"Next Level: " + actor.isMaxLevel() ? "--" : (actor.nextRequiredExp() + " EXP")
Sadly, this did not work either. It only ever executes the first code behind the condition.
Meaning it only displays "--" at all levels or it displays the EXP needed (if i flip the two codes around).
I tried this with lvl 1, lvl 100 (I set the max level to 100) and lvl 99 (i reverted back to default maxlevel for testing)

Also, when I flipped the code;
"Next Level: " + actor.isMaxLevel() ? (actor.nextRequiredExp() + " EXP") : "--"
It did not even display the "Next Level: " at the beginning.

Is there a way to check for the actors level rather than isMaxLevel()?
I did try this, but I am afraid it is not proper JS code and thus it did not work either:
"Next Level: " + actor.level === 100 ? "--" : (actor.nextRequiredExp() + " EXP")

But I appreciate your help anyways!
Try this:

Code:
actor.isMaxLevel() ? "Next Level: ---" : "Next Level: " + actor.nextRequiredExp() + " EXP"
Do you know why my snippet wouldn't have displayed properly? I feel like it's not a Javascript problem, but with how MV's engine is parsing it.
@Trihan Oh my god you are truly a lifesaver!
This is exactly what I needed, thank you so much!

You helped me so much already, I might aswell credit you in my project 😀
Do you know why my snippet wouldn't have displayed properly? I feel like it's not a Javascript problem, but with how MV's engine is parsing it.
It's something weird with having an in-line if statement as part of a string. It only seems to work if the if statement is first and contains the entire two strings you want to show.
Thanks, that's good to know.
"Next Level: " + actor.isMaxLevel() ? "--" : (actor.nextRequiredExp() + " EXP")
Do you know why my snippet wouldn't have displayed properly? I feel like it's not a Javascript problem, but with how MV's engine is parsing it.
It's something weird with having an in-line if statement as part of a string. It only seems to work if the if statement is first and contains the entire two strings you want to show.

The reason it doesn't work is because of order of operations. JavaScript parses it as if you wrote it like this:

JavaScript:
("Next Level: " + actor.isMaxLevel()) ? "--" : (actor.nextRequiredExp() + " EXP")

So the "condition" is the string "Next level: true" or "Next level: false". Using a string as a condition is considered true, so it always displays "--" as a result.

The solution is to put explicit parentheses around the conditional operator:

JavaScript:
"Next Level: " + (actor.isMaxLevel() ? "--" : (actor.nextRequiredExp() + " EXP"))

"Next Level: " + actor.level === 100 ? "--" : (actor.nextRequiredExp() + " EXP")
This is proper JS code, for the record, though it still has the above problem.

Code:
actor.isMaxLevel() ? "Next Level: ---" : "Next Level: " + actor.nextRequiredExp() + " EXP"
This version could be further refined with MV's format function:

JavaScript:
actor.isMaxLevel() ? "Next level: ---" : "Next level: %1 EXP".format(actor.nextRequiredExp())
All good points. I forgot JS had an sprintf equivalent.
All good points. I forgot JS had an sprintf equivalent.
That format function is an MV extension, for the record. The JS built-in version would be template literals:

JavaScript:
`Next level: ${actor.nextRequiredExp()} EXP`

But MV's version has the advantage of not dumping the code right into the string, which is better for localization. (Though if you assigned the EXP to a variable and interpolated just the variable into the template literal, that wouldn't be an issue for localization, assuming there's some way to get back the actual template.)
Ah, cool. I haven't fully read through all the extensions the core js added yet.
The reason it doesn't work is because of order of operations. JavaScript parses it as if you wrote it like this:

JavaScript:
("Next Level: " + actor.isMaxLevel()) ? "--" : (actor.nextRequiredExp() + " EXP")

So the "condition" is the string "Next level: true" or "Next level: false". Using a string as a condition is considered true, so it always displays "--" as a result.

Thank you, that makes sense. I was treating the plus signs like output dividers in a cout function, which they're clearly not if I'd thought about it for a moment.
Thank you, that makes sense. I was treating the plus signs like output dividers in a cout function, which they're clearly not if I'd thought about it for a moment.
Um, if you replaced the + with a << you'd have the same problem, actually.
Um, if you replaced the + with a << you'd have the same problem, actually.
You could be right, I haven't gotten to use anything newer than fricking C for several years. It would definitely function as intended in printf, as at that point they're just arguments for the function. I'm re-familiarizing myself with Javascript as I get back into working with MV.
Yeah, of course it would be fine in printf() or MV's ''.format().

In general, if something isn't working, adding parentheses to clarify order of operations can never hurt and will often help.

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-display-currentexp-tonextlevelexp.123997/