$gameVariables.value(20)._hp works but not $gameVariables.value(20).gainHp(6000);

Antera

Villager
Member
Joined
Jan 15, 2017
Messages
38
Reaction score
5
First Language
EN & FR
Primarily Uses
Hello,

Could you please help me with JS and explain to me why $gameVariables.value(20)._hp = 4000; works but not
$gameVariables.value(20).gainHp(4000); ?

Should I do something like this ?
var tmpActor = new Actor($gameVariables.value(20).actorid);
tmpActor.gainHp(4000);

Actor is taken in the formula box of the item. It's an object (when I display \V[20] I got [Object object]) and called in the common event :

ppp1.png ppp2.png

Many many thanks !
 

Antera

Villager
Member
Joined
Jan 15, 2017
Messages
38
Reaction score
5
First Language
EN & FR
Primarily Uses
I had hope changing the formula to :
$gameVariables.setValue(20,b.id);

And the script to :
$gameActors.actor($gameVariables.value(20)).gainHp(2000);

But error :-(
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,932
Reaction score
3,161
First Language
English
Primarily Uses
RMMZ
The problem is that gainHp only recovers HP, it doesn't affect max. This actually does work, but the actor would have to be damaged for you to notice the effect.

There's a reason item effects don't have an option to raise max HP: it's not that easy. The thing is, Game_Battler's mhp property returns params(0), which is a function that among other things takes paramBase(0) as its base value, which actually gets its value from the array of stats associated with the character's current class.

What you want to do is add to the battler's _paramPlus[0] variable instead, which will make their max HP higher.
 

Antera

Villager
Member
Joined
Jan 15, 2017
Messages
38
Reaction score
5
First Language
EN & FR
Primarily Uses
There's a reason item effects don't have an option to raise max HP
Well items do have an effect to grow max HP .itemEffectGrow()
Effects > Other > Grow > Max HP
add to the battler's _paramPlus[0] variable
Oh yes ! Thank you !
So : $gameVariables.value(20)._paramPlus[0] += 2000;

EDIT, needed to refresh() the actor object to see the change :

$gameVariables.value(20)._paramPlus[0] += 2000;
$gameVariables.value(20).refresh();
$gameVariables.setValue(20,0);
 
Last edited:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,932
Reaction score
3,161
First Language
English
Primarily Uses
RMMZ
Ah, yeah, sorry. You could use the battler's addParam(0) function, which internally just adds to _paramPlus and refreshes.
 

Antera

Villager
Member
Joined
Jan 15, 2017
Messages
38
Reaction score
5
First Language
EN & FR
Primarily Uses
Ah, yeah, sorry. You could use the battler's addParam(0) function, which internally just adds to _paramPlus and refreshes.
Thanks, perfect !
Feels good to use code instead of those preset options

PS : I cant use V[41] or $V[41] instead of $gameVariables.value(41) ? I have error with both but I read that it was possible
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
3,932
Reaction score
3,161
First Language
English
Primarily Uses
RMMZ
Try a small v, it's case-sensitive.
 

Latest Threads

Latest Posts

Latest Profile Posts

since all my maps are hand drawn... I admit, I super envy those who can make the tileset's work. I'm garbage at mapping, but slightly less bad at just drawing my own areas. plus it's easier to draw my own sprites than edit others to look like my characters.
Guys, I made a trailer! And, I also launched the Steam page! If you would like to support the game, please Wishlist it :ahappy: ->
working on some tilesets _ノ乙(、ン、)_

CIBl8xT.png


Oq8WKHX.png
aww man, color hex code #C4C4C4 doesn't work for the tint value in this scene I need something darker, which stinks just because I liked that one it was my favorite plastic explosive three times...#696969 (nice) should work better (WHY IS MY BRAIN LIKE THIS)
Tell it to me straight, doc. If I've been trying to piece together a "shorter" game to learn stuff outside of game jams... am I just running away from my WIP? :v

Forum statistics

Threads
117,284
Messages
1,106,127
Members
153,467
Latest member
Kip_
Top