[RMMV] Display CurrentEXP / ToNextLevelEXP?

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
194
Reaction score
293
First Language
German
Primarily Uses
RMMV
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
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
Try

"Next Level: " + actor.nextRequiredExp()
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
194
Reaction score
293
First Language
German
Primarily Uses
RMMV
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.
 
Last edited:

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,116
Reaction score
808
First Language
English
Primarily Uses
RMMV
I think you can use "actor.isMaxLevel()" in a conditional to do what you described.
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
194
Reaction score
293
First Language
German
Primarily Uses
RMMV
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.
 

ATT_Turan

Veteran
Veteran
Joined
Jul 2, 2014
Messages
74
Reaction score
27
First Language
English
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")
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
194
Reaction score
293
First Language
German
Primarily Uses
RMMV
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!
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
Try this:

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

ATT_Turan

Veteran
Veteran
Joined
Jul 2, 2014
Messages
74
Reaction score
27
First Language
English
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.
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
194
Reaction score
293
First Language
German
Primarily Uses
RMMV
@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 :D
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
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.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
487
Reaction score
212
First Language
English
Primarily Uses
RMMV
"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())
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
All good points. I forgot JS had an sprintf equivalent.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
487
Reaction score
212
First Language
English
Primarily Uses
RMMV
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.)
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,373
Reaction score
1,548
First Language
English
Primarily Uses
RMMV
Ah, cool. I haven't fully read through all the extensions the core js added yet.
 

ATT_Turan

Veteran
Veteran
Joined
Jul 2, 2014
Messages
74
Reaction score
27
First Language
English
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.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
487
Reaction score
212
First Language
English
Primarily Uses
RMMV
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.
 

ATT_Turan

Veteran
Veteran
Joined
Jul 2, 2014
Messages
74
Reaction score
27
First Language
English
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.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
487
Reaction score
212
First Language
English
Primarily Uses
RMMV
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.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Finding it amusing that people are posting support questions in new threads for an engine that isn't even released yet. Touch and Archeia are the only ones authorised to say anything, and there's only one active thread where they'll be answering questions.
I think my goal for MZ ... is to actually release a game and not have twenty technical demos and debugging projects. Let's see if I can manage that. ;o
I am starting to enjoy writing. I never thought I would enjoy it since my dyslexia was holding me back so much.
Thanks to the community here :)
For those interested chapter 2 and 3 are available to read here:
I'm having a fun time working with the MZ RTP. The waterfall hasn't changed, though, so I'm wondering if they didn't make a new one or if they forgot to put it in...

good progress on the typescript Definitions files almost done all the Manager and yet I still have to do the Battle Manager...who is seriously so much data lol

Forum statistics

Threads
100,651
Messages
978,090
Members
132,260
Latest member
enciasduras
Top