Scale Width for Picture w/ Script call

I am attempting to have a picture become scaled to a width based on a variable. I attempted using

JavaScript:
$gameScreen.picture(19)._scaleX() = parseInt($gameVariables.value(21) *3)

The picture (19) is 100 px wide. Variable 21 is equal to 5 so I am trying to get the width to therefore be 15 px. Am I going about this wrong?
It's scaleX(), not _scaleX() - and it expects a number passed in as an argument, you can't use = to set the result of a function call to something.
Thank you for the explanation, Turan!

I tried passing a value into scaleX() but still did not have any effect on the width of the picture. I attempted the following


JavaScript:
var valScale = $gameVariables.value(21) * 3;
$gameScreen.picture(19).scaleX(valScale);

EDIT: Also tried this

Code:
var valScale = $gameVariables.value(21) * 3;
var pic = $gameScreen.picture(19);
pic._duration = pic._wholeDuration = 5;
pic._targetScaleX = valScale;
If you're having troubles with it, why not just use the whole 'move picture' script from the script list:

$gameScreen.movePicture(pictureId, origin, x, y, scaleX, scaleY, opacity, blendMode, frames, easing);

Just replace the scaleX with your variable value.

EDIT: Or use the show picture script, depending on what you want.
One small tip from me:

The underscore symbol in front of a variable or method is the common way to tell that this variable or method is internal and should not be called by anyone. Only when there's no other way or you know what you're doing.

Usually, there's a method or variable right next to it that you can use, in this case, it's scaleX as already explained.
If you're having troubles with it, why not just use the whole 'move picture' script from the script list:

$gameScreen.movePicture(pictureId, origin, x, y, scaleX, scaleY, opacity, blendMode, frames, easing);

Just replace the scaleX with your variable value.

EDIT: Or use the show picture script, depending on what you want.
Thanks, RPGLord.

I did try that one and could not get it to work either. Additionally, I ideally would only want to change the X scale and not have to re-enter the other inputs to keep the script dyanmic.
Sorry, my prior reply was incorrect.

scaleX() does not take an argument because it's not a way to modify anything - it's a getter function. I dunno what the heck I was looking at, but I hadn't had breakfast yet.

There is no provided function to do what you're looking for, outside of the Move Picture command that @rpgLord69 suggested.

So while @Aerosys is absolutely correct and it's best practice to avoid modifying internal properties, what you'd need to do here is edit _scaleX and then update the display.
Code:
$gameScreen.picture(19)._scaleX = $gameVariables.value(21)*3;
$gameScreen.picture(19).update();
Sorry, my prior reply was incorrect.

scaleX() does not take an argument because it's not a way to modify anything - it's a getter function. I dunno what the heck I was looking at, but I hadn't had breakfast yet.

There is no provided function to do what you're looking for, outside of the Move Picture command that @rpgLord69 suggested.

So while @Aerosys is absolutely correct and it's best practice to avoid modifying internal properties, what you'd need to do here is edit _scaleX and then update the display.
Code:
$gameScreen.picture(19)._scaleX = $gameVariables.value(21)*3;
$gameScreen.picture(19).update();
Ah Ha! That update did function did it! It still seems to go back to the original when I loop it but that is a minor issue I'll workshop.
Code:
var valScale = $gameVariables.value(21) * 3;
var pic = $gameScreen.picture(19);
pic._duration = pic._wholeDuration = 5;
pic._targetScaleX = valScale;
Without plugins, assuming your variable ID & picture ID are correct, this should definitely work. (I just tested it to be sure, since it's almost identical to one of the Script Call List examples.)

It eases the picture to the specified X-scale over 5 frames. However, it will be cancelled if you update this picture's target X scale during those 5 frames, e.g. with this kind of script call or a Move Picture command.

You should match the duration to the update/loop frequency. E.g. if you're updating every frame, use a duration of 1 instead of 5, so it rescales immediately.

Turan's approach may work, but could also result in side-effects because update assumes it will only be called once per mechanical frame. Actually, I believe the update call is unnecessary, because pictures update after events each frame (which is why a duration of 1 frame causes an immediate response).
I believe the update call is unnecessary, because pictures update after events each frame (which is why a duration of 1 frame causes an immediate response).
At least in my brief testing, typing the commands into the console, I didn't see a change until I manually called update().
At least in my brief testing, typing the commands into the console, I didn't see a change until I manually called update().
😅 That's odd. I just tested with no plugins in MZ v1.7.0 and MV v1.6.2. In both cases I did this:
  • Map event -> Show Picture 1 at 100% width,
  • Console -> $gameScreen.picture(1)._scaleX = 200;
For MV the expected result was immediate: picture doubled in width. For MZ I had to re-focus the game window, because it pauses when out of focus. Tried in MZ with a Script command instead of console: immediate result. Maybe you're using an older core script version and/or plugins?

I suggested _targetScaleX instead because when the picture's move duration is more than 0, the target value is used to update the actual value each frame based on the remaining duration.
For MZ I had to re-focus the game window, because it pauses when out of focus.
That was it 😀

Original thread: https://forums.rpgmakerweb.com/threads/scale-width-for-picture-w-script-call.161876/