Changing Parameter Values Via Script

Status
Not open for further replies.

Kaza

Villager
Member
Joined
Jan 12, 2016
Messages
22
Reaction score
2
First Language
English
I'm having some difficulties with the parameters as they seem to be a bit weird, not exactly as shown in the script call sheet. When viewing the parameters you need to use parenthesis like so.

$gameMessage.add(String($gameActors.actor(1).param(2)))

However when I try to edit the value using parenthesis I get an error. So I tried to use the brackets as shown in the script call sheet, like so

$gameActors.actor(1).param[2] = 1

I no longer get an error but the value doesn't change either. How do I set the value of the parameter?
 

waynee95

Lunatic Coder
Veteran
Joined
Jul 2, 2016
Messages
665
Reaction score
557
First Language
German
Primarily Uses
RMMV
When you wanna add to a parameter you need to use
Code:
$gameActors.actor(x).addParam(paramId, value);
 

Kaza

Villager
Member
Joined
Jan 12, 2016
Messages
22
Reaction score
2
First Language
English
Is there a way to simply set a value rather than add/subtract?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,103
Reaction score
10,488
First Language
Czech
Primarily Uses
RMMV
No wonder $gameActors.actor(1).param(2) = 1; throws you an error.
$gameActors.actor(1).param(2) is a function. And functions are immutable, so they cannot be assigned a value. You can only call a function.
However, the number in params is equivalent to this:
0 - mhp
1 - mmp
2 - atk
3 - def
4 - mat
5 - mdf
6 - spd
7 - luk

So since now we know that param 2 is attack, which is a property and not a function, we can change it like this:
$gameActors.actor(1).atk = 1;

I'm not going to go in too many confusing details, this is object oriented programming and I'm not sure what's your skill in Javascript. I don't want to confuse you too much as well.
 

waynee95

Lunatic Coder
Veteran
Joined
Jul 2, 2016
Messages
665
Reaction score
557
First Language
German
Primarily Uses
RMMV
@Poryg
$gameActors.actor(1).atk = 1;

Would not work, because "atk" is only read-only (it's only a getter, not a setter). The only way to change parameters is what I posted.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,103
Reaction score
10,488
First Language
Czech
Primarily Uses
RMMV
I'll be damned, I completely forgot that you can change only hp, mp and tp.
So, if we simplify it to an unified command, in order to set the param to value x, you need to subtract value - x:
$gameActors.actor(1).addParam(paramId, Math.abs ($gameActors.actor(1).param(paramId) - number) * -1)
Well, that doesn't look too beautiful xD

EDIT: No, that's not correct... Doesn't work for number greater than parameter... So it's equivalent to
$gameActors.actor(1).addParam (paramId, $gameActors.actor(1).param(paramId) - number)
 

Wavelength

Edge of Eternity
Global Mod
Joined
Jul 22, 2014
Messages
5,144
Reaction score
4,450
First Language
English
Primarily Uses
RMVXA
Is there a way to simply set a value rather than add/subtract?
Find the difference between the current value and the value you want to set, then use the addParam method to add the difference (which may be negative).

I'm not 100% sure but I think this would be the correct form:

cur_par = $gameActors.actor(x1).param(x2);
set_par = x3;
diff_par = set_par - cur_par;
$gameActors.actor(x1).addParam(x2, diff_par);


where x1 is the actor ID you want to do it for, x2 is the index of the Parameter you want to work with (like 2 for ATK), and x3 is the value you want to set that Parameter to.

You could also shorten it to this if you're looking to do it all on one line:
$gameActors.actor(x1).addParam(x2, (x3 - ($gameActors.actor(x1).param(x2))));
 

Kaza

Villager
Member
Joined
Jan 12, 2016
Messages
22
Reaction score
2
First Language
English
You could also shorten it to this if you're looking to do it all on one line:
$gameActors.actor(x1).addParam(x2, (x3 - ($gameActors.actor(x1).param(x2))));
Thanks! I actually was realizing that I could do this as I was eating lunch. I originally had tried to simply use the event process to subtract 9999 from the parameter to reset it to 1, but then I found out that the game would return 1, but the parameter would actually store the negative number.
 

Guanto

Auteur
Veteran
Joined
Jul 18, 2018
Messages
111
Reaction score
10
First Language
English
Primarily Uses
RMMV
You could also shorten it to this if you're looking to do it all on one line:
$gameActors.actor(x1).addParam(x2, (x3 - ($gameActors.actor(x1).param(x2))));
First off I love that you threw down with this in the face of "can't be done". It's one of my favorite things that happens on established forums.

Though I admittedly also find it odd that we can't just get to that base parameter ("cur_par" if you will) and tweak it directly.

Now my question. Your exact solution here, but for Ex and Sp parameters. Possible?
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,002
Reaction score
11,318
First Language
English
Primarily Uses
RMVXA
[necro]Guanto[/necro]
It is also hi-jacking. Please start your own thread.

[mod]Closing[/mod]
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Haven’t gotten over a mentor’s promotion. He deserves it, but he was the first person to be nice to me at work. It’s been hard for me to let him go.
So its confirmed MZ will have tile size locked at 48x48. So thats extremely lame. Still probably going to get it for the assets but Im gonna pout the whole time.
A friend used to ask why I don't colorize most of my drawings? The answer: I'm colorblind.
Thought something big was going down when I saw a riot van and two cop cars outside my home. Nope. Just multiple calls about one man kicking off in the street. xD
RPG Maker MZ does confirm in its RPG Maker website blog about new features. Graphics of course look gorgeous, but how about what keeps the engine together?

Forum statistics

Threads
99,341
Messages
964,294
Members
130,945
Latest member
studiojap
Top