How to Change One Variable to Equal Another?

So what I’m trying to do is to have MP that can go above 100. If Max MP was at 100, I could use *stat_chart and the % bar to express how much MP I have out of the total. But how do I do this if I want the total to be more than 100 and for the current MP not to go over the Max MP?

So what I did so far is:

*create CurrentMP 0
*create MaxMP 5

and in my stat sheet I have

Mana: {CurrentMP}/{MaxMP}

Which at the start of the game reads in the stat sheet as follows:

Mana: 0/5

However, right now if I have two choices that would add +5MP, you end up with Mana: 10/5.

What I want to do here is create a *set command that would set the CurrentMP variable displayed to equal the MaxMP variable. Or alternatively, to have an *if condition that shows CurrentMP/Max MP if Current MP is less than Max MP, and shows only Max MP if Current MP is equal to or greater than Max MP

I’ve tried directly comparing variables, setting temporary variables to equal to the CurrentMP and MaxMP variables as defined in the startup and making a subroutine to compare them separately. Any idea how I might do this?

PS: I realize that I can just show MP as a single number of available and usable MP at any one point and not have a max MP cap, and that’s what I’m going to do if I can’t figure it out

1 Like

I’m sorry if I don’t understand, I’m borderline asleep.

*if CurrentMP >= MaxMP
  *set CurrentMP = MaxMP
  (do nothing and just show the CurrentMP)

That’s all I can do now. Going to sleep now byee.

You might need the “3rd variable” here. The currentMP, the MPcap, and the displayMP.

CurrentMP is the actual Mana you have in-game.
MPcap is the max mana you can have, though it’ll never be the case if I understand your example.
DisplayMP would be the one showing in the stats screen instead of currentMP. You can alter this as much as you like without changing the actual mana you have.

Thanks guys! I think I figured out how to do it. I did it without the third variable, this will make my code a little longer, but it seems to work.

Instead of doing the check to see if currentMP is greater than maxMP when I’m displaying it, I kept the stat sheet code simple as Mana: {CurrentMP}/{MaxMP} and instead did the check each time I increase MP. So instead of going *set CurrentMP +1 when MP is gained, I do the check:
*if CurrentMP < MaxMP
*set CurrentMP+1

this way if adding more MP would put me over the max, it simply does not add the MP. I can play around with this, but so far it works.

1 Like

Have you thought of doing this…

You're training increases your power.
*set max_mp +5

This way you won’t have to check the max_mp the only issue with this is the current_mp won’t change to the max_mp if that’s what happens when you increase your mp so you could do just add an extra line.

You're training increases your power.
*set max_mp +5
*set current_mp max_mp

for some reason when I was trying to do that last line *set CurrentMP MaxMP last night it was giving me errors. Tried it today and it works. that effectively works as a cap now by setting up
*if CurrentMP > MaxMP
*set CurrentMP MaxMP
*if CurrentMP < 0
*set CurrentMP 0

I have no idea why it wasn’t working last night lol. Maybe I was just tired and was overlooking something obvious. Anyways, thanks so much! It all works perfectly now :slight_smile: without having to repeat the check each time I make the change. I put the MP cap check in the stats page

1 Like

Be careful of putting

*set CurrentMP MaxMP

In the stat screen

Because players will reset their mp every time they go into the stat screen so they can refresh it whenever they want.

My understanding is that this is what a *gosub is for. The wiki explicitly mentions it being used to cap stats. Read the choice script wiki article on gosubs and see if that is what you want. If so, just put it at the bottom of your scene file(s) with a *return command at the end.

Good point. I think it works ok though because I have that command executing only if CurrentMP is already greater than MaxMP

I don’t know if I understand this as a whole but I think putting the MP cap check only in stat page means that the player’s MP will not be capped until they visit the stat page.

Be careful with it as the currentMp can still go over the maxMP if the player manages to stay off the stats page. If that happens, the player could use those excess MP.


Suppose the maxMP is 10 and currentMP is 5. In the next two pages, the player receives each 5 MP. This results in 15 currentMP.

If the player visits the stats page, the MP will be capped 10/10. It’s fine. But, if the player don’t, the MP will still 15/10.

Capping the MP only in stats page will be fine as long as this is not a problem.

1 Like

You are absolutely correct and I thought of that problem after I posted this, since the check is done only when you ‘run’ the stats page by loading it up. I didn’t notice it at first since it appeared to work just fine, but at least I have the code. I’ll make it into a subroutine and use the *gosub command to check whenever I do anything that would change the mana.

Thank you! :slight_smile:

This topic was automatically closed 24 hours after the last reply. If you want to reopen your WiP, contact the @moderators.