[RMMV] Display CurrentEXP / ToNextLevelEXP?

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
204
Reaction score
317
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,379
Reaction score
1,559
First Language
English
Primarily Uses
RMMV
Try

"Next Level: " + actor.nextRequiredExp()
 

ScorchedGround

Blizzards most disappointed fan
Veteran
Joined
Apr 12, 2020
Messages
204
Reaction score
317
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
809
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
204
Reaction score
317
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
75
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
204
Reaction score
317
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,379
Reaction score
1,559
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
75
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
204
Reaction score
317
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,379
Reaction score
1,559
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
493
Reaction score
216
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,379
Reaction score
1,559
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
493
Reaction score
216
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,379
Reaction score
1,559
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
75
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
493
Reaction score
216
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
75
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
493
Reaction score
216
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 Profile Posts

And back. Trying to work online with no internet for 1.5 days was...interesting. I felt like a character in a old Sierra game trying to find internet due to all the hoops I had to jump through just to get online for work.
grief... if MV didn't have certain plugins already, I think I'd upgrade to MZ. seeing like 10 MV plugins in 1 MZ one is hilariously convenient lol.
Have you already checkes out my mapping tutorial on the blog? I would love to hear your feedback and things you'd like to see in the future!

one of character for my upcoming game idk how to design o_O

Designing patches that can 'augmented' to clothing based armor. Such good fun. A bit time consuming due to the need to create image displays, but the patches are limited so it's not too tiring.
Note: lol, posting this made me find a couple mistakes.

Forum statistics

Threads
100,736
Messages
978,938
Members
132,359
Latest member
PhilKeepItReal
Top