MV How to get non referenced mp?

I am looking for a way to store mp into a variable, then change actor mp and use the stored variable later, but when I get the variable I get an object reference.

Lets imagine my character has 100 MP and I make this damage formula:

x=a.mp; a.gainMP(-90); x*2

the damage done is 20 because I substracted 90 mp and x is a reference of the actor mp.

How can I store this MP and get 200 damage?


Oh forget it, it wasn't a reference but a elemental rate causing the problem.
You don't appear to actually be declaring x, which means it becomes a global object - if you're using similar syntax anyplace else, that could be the cause of your problem as you'll actually be trying to work with the x you made someplace else.

You should use var x or let x, and go from there.

Now, .mp is actually a...I don't know the correct terminology, function in a hash table, that returns the ._mp member variable of an actor. But it does return that value, so your code should work as expected.

You could change it to reference a._mp, but I would also suggest you change it to declare your variable.

Closing at OP's request.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-non-referenced-mp.146737/