Error : "Cannot read property "clamp" of undefined" when making a switch statement

Hi !
In my game at one point I have an even that chooses a random number, then displays a picture according to that number.
To save up on event space, I programmed it using a switch statement in a script block, but it crashes...

1771537314016.png

^ Here's my code for choosing the random number, and the switch statement

1771537364803.png

^ And here's the error I get...

My guess is that probably I bungled the statement by trying to have it be as compact as possible... But I really don't know !! Thank you for your help !
In the future, when you encounter an error like this, press F12, select the "console" tab, click the small triangle next to the error to expand it, and screenshot that. It has a lot more information that's typically quite useful for diagnosing errors, even if in this specific case it's not needed.


This function requires quite a few more arguments, namely: pictureId, name, origin, x, y, scaleX, scaleY, opacity, blendMode. You've only given it the first 2; it still needs 7 more. E.g. $gameScreen.showPicture(99, 'trc-1-1', 1, 50, 50, 100, 100, 255, 0);

Try using it from the console first until you get it to work, and only then make scripts with it.

You can also simplify your script to: $gameScreen.showPicture(99, 'trc-1-' + $gameVariables.value(69), <remaining arguments>);
What I'd recommend doing here is to install my SFG_SwitchCommand plugin and write your switch statement with that. That'll allow you to directly use the Show Picture command, so you don't have to worry the order and number of arguments to the script call.

The end result would look something like this:
Code:
◆Plugin Command:switch @69
◆Show Choices:1, 2, 3, 4, 5, 6 (Window, Right, #1, #2)
:When 1 
  ◆Show Picture:#99, trc-1-1, Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 2 
  ◆Show Picture:#99, trc-1-2, Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 3 
  ◆Show Picture:#99, trc-1-3, Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 4 
  ◆Show Picture:#99, trc-1-4 Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 5 
  ◆Show Picture:#99, trc-1-5 Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 6 
  ◆Show Picture:#99, trc-1-6 Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:End
◆Show Choices:7, 8, 9 (Window, Right, #1, #2)
:When 7 
  ◆Show Picture:#99, trc-1-7 Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 8 
  ◆Show Picture:#99, trc-1-8, Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:When 9 
  ◆Show Picture:#99, trc-1-9, Upper Left (0,0), (100%,100%), 255, Normal
  ◆
:End

Certainly it's a lot more verbose, but it's much, much easier to edit.
You can also simplify your script to: $gameScreen.showPicture(99, 'trc-1-' + $gameVariables.value(69), <remaining arguments>);
Oh thanks a lot !! That will save me a lot of space, I didn't know you could add strings like that in parameters...
Also yeah, I thought I could skip the arguments after the image name, and it would use a default... I stand corrected !
What I'd recommend doing here is to install my SFG_SwitchCommand plugin and write your switch statement with that. That'll allow you to directly use the Show Picture command, so you don't have to worry the order and number of arguments to the script call.
I didn't know there was a plugin like that ! But it uses a lot of space... maybe ill consider it, but ill stick to scripts otherwise.

Original thread: https://forums.rpgmakerweb.com/threads/error-cannot-read-property-clamp-of-undefined-when-making-a-switch-statement.182530/