Image changes every map transfer, but randomly.

Hello!

I'm quite new to RPGMV, I am very new to scripting too.
For now, I have a simple script that shows image in a map, that changes when I transfer to another map.

What I want is for that image change to be randomized using a set of images in a folder.
I know it is possible, since an RPGMV game I played have this mechanic. I couldn't contact the game maker so I have to ask here if anyone knows how it was done.

The simple script I'm using is:

$gameScreen.showPicture(1, 1, 0, 720, 404, 100, 100, 255, 0);

With the first 2 "1, 1" as the ID picture and file name.
That script call has some incorrect syntax - the filename needs to be a string. If you're not referencing a variable that is a string, you need to put the name in quotations.

You could try something like this in a Script box.
Code:
let picIds=[1, 2, 5, 8]; // These are the IDs you want to choose from
let picNames=["file1", "face_2", "picture10", "choice4"]; // These are the associated filenames

let randChoice=Math.randomInt(picIds.length);
$gameScreen.showPicture(picIds[randChoice], picNames[randChoice], 0, 720, 404, 100, 100, 255, 0);

You could probably combine the two arrays into a hash table or vector, but I think this is simple enough.
That script call has some incorrect syntax - the filename needs to be a string. If you're not referencing a variable that is a string, you need to put the name in quotations.

You could try something like this in a Script box.
Code:
let picIds=[1, 2, 5, 8]; // These are the IDs you want to choose from
let picNames=["file1", "face_2", "picture10", "choice4"]; // These are the associated filenames

let randChoice=Math.randomInt(picIds.length);
$gameScreen.showPicture(picIds[randChoice], picNames[randChoice], 0, 720, 404, 100, 100, 255, 0);

You could probably combine the two arrays into a hash table or vector, but I think this is simple enough.

I will try it out, just for clarification, how should I write these

"picIds[randChoice], picNames[randChoice]" ?

like so "1, 2[randChoice], 1, 2[randChoice]"?

assuming the Ids and names are both 1,1 and 2,2

Also, do I put the script in an event for every map? or can I make something like a common event, triggered by map transfer?
I will try it out, just for clarification, how should I write these

"picIds[randChoice], picNames[randChoice]" ?
Exactly the same as ATT_Turan wrote it, do not change anything on that line. You only need to change the first two lines to add your filenames and ids.

Also, do I put the script in an event for every map? or can I make something like a common event, triggered by map transfer?

The simplest way would be to put it in a common event, which you can trigger with this plugin: https://forums.rpgmakerweb.com/index.php?threads/map-transfer-common-event.139917/.
I will try it out, just for clarification, how should I write these

"picIds[randChoice], picNames[randChoice]" ?

like so "1, 2[randChoice], 1, 2[randChoice]"?

assuming the Ids and names are both 1,1 and 2,2
I don't really understand the question, I gave you the exact code to copy and paste. The only thing you need to edit are the two lists of IDs and names.

Also, do I put the script in an event for every map? or can I make something like a common event, triggered by map transfer?
There's not such a thing as a "common event triggered by map transfer."

If you want something to happen once every time you load a map, you make an Autorun event that does the stuff then has Erase Event at the bottom.
I don't really understand the question, I gave you the exact code to copy and paste. The only thing you need to edit are the two lists of IDs and names.


There's not such a thing as a "common event triggered by map transfer."

If you want something to happen once every time you load a map, you make an Autorun event that does the stuff then has Erase Event at the bottom.
Okay, I will try it once I get home so I could understand better. Thank you, and sorry, I am really new to all these.
Exactly the same as ATT_Turan wrote it, do not change anything on that line. You only need to change the first two lines to add your filenames and ids.



The simplest way would be to put it in a common event, which you can trigger with this plugin: https://forums.rpgmakerweb.com/index.php?threads/map-transfer-common-event.139917/.
Thank you! I will try them out.

Original thread: https://forums.rpgmakerweb.com/threads/image-changes-every-map-transfer-but-randomly.155138/