Heal player per life percentage

Morning, Night or Evening to all of you!

Well, I was trying to do this script thing and I have a problem here.

$gameActors.actor(1).gainHp(0.04*(m.mhp));

So I want this script call to heal my actor for 4% of his HP when the script is active. Sadly this doesn't happen
when I use this command, but it happens if I use number values instead, just like this:

$gameActors.actor(1).gainHp(100);

What did I do wrong?
The shortcut for "user" is a, and the shortcut for "target" is b... not m. If you are doing this outside of a battle formula, you need to reference the object (so $gameActors.actor(1) in your case) rather than use a shortcut.
Mr. Wavelength, you're a god.

What you told me was very helpful. For your contribuition, you've been honored.
Again, you have my thanks.
I'm also trying to round up my heal, because sometimes it comes with decimal values.

tried to do something like this but it didn't work.

Spoiler: Script
var m = $gameActors.actor(2)

Math.round($gameActors.actor(2).gainHp(0.04*(m.mhp)));
dont use m.mhp on the end, just mhp can do because m.mhp has no strings.
if mhp dont work, use ._mhp, i dont see why you use var though.
I'm also trying to round up my heal, because sometimes it comes with decimal values.

tried to do something like this but it didn't work.

Spoiler: Script
var m = $gameActors.actor(2)

Math.round($gameActors.actor(2).gainHp(0.04*(m.mhp)));

It's a logic error. gainHp() doesn't return a value, so you won't be able to round it. Try:

$gameActors.actor(2).gainHp(Math.round(0.04*(m.mhp)));

or, to ensure you're always rounding up:

$gameActors.actor(2).gainHp(Math.ceil(0.04*(m.mhp)));
It's a logic error. gainHp() doesn't return a value, so you won't be able to round it. Try:

$gameActors.actor(2).gainHp(Math.round(0.04*(m.mhp)));

or, to ensure you're always rounding up:

$gameActors.actor(2).gainHp(Math.ceil(0.04*(m.mhp)));
It worked pretty fine! Thank you all guys!

Original thread: https://forums.rpgmakerweb.com/threads/heal-player-per-life-percentage.110296/