how do i make a random image pool for an event?

suprise! im back again 😔
ive been working on a cafe minigame, where a random customer comes up and asks for an order
1699738845057.png

ive gotten basically everything set up besides the random character part (which will function on a random image picked from a pool of images, that uses a variable)
i cant seem to get this to work and i need help with it
Something like this:
JavaScript:
  var imagePool = ['image1', 'image6', 'image8'];
  var randomIndex = Math.floor(Math.random() * imagePool.length);
  $gameScreen.showPicture(1, imagePool[randomIndex], "Center", 600, 300, 100, 100, 255, "Normal")
The first line is the names of your image files and the last line depends on what your show image command looks like.
Something like this:
JavaScript:
  var imagePool = ['image1', 'image6', 'image8'];
  var randomIndex = Math.floor(Math.random() * imagePool.length);
  $gameScreen.showPicture(1, imagePool[randomIndex], "Center", 600, 300, 100, 100, 255, "Normal")
The first line is the names of your image files and the last line depends on what your show image command looks like.
it comes up with this error for some reason
1699743052255.png
it comes up with this error for some reason
View attachment 283490
It means you edited or deleted imagePool from the first line. Post what your script looks like.
It means you edited or deleted imagePool from the first line. Post what your script looks like.
1699743856160.png

ps: i tried to add more images on, i'm not sure if that's the issue
also i didn't delete the rest, i couldn't fit it all into 1 screenshot
The entire thing should be inside the script box thingy. Where is the rest of it?
View attachment 283492
ps: i tried to add more images on, i'm not sure if that's the issue
also i didn't delete the rest, i couldn't fit it all into 1 screenshot
Did you do this all as separate script commands for each individual line rather than putting the whole thing in one input box?
alright, i ended up fixing it by adding the numbers of the images at the end of this part for some reason, and replacing "imagePool[randomIndex]" with "imagename"
JavaScript:
  $gameScreen.showPicture(65, imageName, "Center", 409, 312, 100, 100, 255,);
thank y'all yet again, i literally don't know what i would do w/o you guys 😤
alright, i ended up fixing it by adding the numbers of the images at the end of this part for some reason, and replacing "imagePool[randomIndex]" with "imagename"
JavaScript:
  $gameScreen.showPicture(65, imageName, "Center", 409, 312, 100, 100, 255,);
thank y'all yet again, i literally don't know what i would do w/o you guys 😤
I guarantee you absolutely did not fix it by doing this unless you added extra code that isn't shown here, because "imageName" otherwise doesn't exist and won't link to anything.
I guarantee you absolutely did not fix it by doing this unless you added extra code that isn't shown here, because "imageName" otherwise doesn't exist and won't link to anything.
OH YEAH sorry about that lol
i forgot to add that i added this
1699748148466.png
i forgot to add that i added this
please do not crop your images but show the full screenshot if you want further help - here or for a different problem.

that is now several times where problems and communications failures were caused by your cutting away important information on your screenshots
OH YEAH sorry about that lol
i forgot to add that i added this
View attachment 283503
That doesn't fix the issue you posted earlier, because the error was with the first or second line, and your new variable declaration requires the first and second line to have no issues.
please do not crop your images but show the full screenshot if you want further help - here or for a different problem.

that is now several times where problems and communications failures were caused by your cutting away important information on your screenshots
i'm sorry about that, i'll not do that next time i need help

thank you for letting me know tho :3
Since the OP wasn't very helpful, I tested it myself and the actual issue is that the blend mode value on the third line needs to be a number and not a string, where Normal is 0, additive is 1, multiply is 2, and screen is 3. So this is the correct code
JavaScript:
var imagePool = ['image1', 'image6', 'image8'];
var randomIndex = Math.floor(Math.random() * imagePool.length);
$gameScreen.showPicture(1, imagePool[randomIndex], "Center", 100, 100, 100, 100, 255, 0);
Also, strictly speaking, the same thing applies to the origin: 0 (top-left) or 1 (center). The core scripts simply do "if origin is 0, top-left; else center", though (cf Sprite_Picture#updateOrigin), so the value "Center" happens to produce the intended result.

Edit: and undefined for the blend mode (as in the OP's "working" showPicture call) probably gets coerced to 0 at some point. My mistake: it actually throws an error, at least for the WebGL renderer. 😴
Edit: and undefined for the blend mode (as in the OP's working showPicture call) probably gets coerced to 0 at some point.
No, if you leave it blank or cut it off like the OP did it throws the "cannot read property length" error.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-a-random-image-pool-for-an-event.162843/