MV Change a Picture's ID with JS

Backstory: I love using JavaScript to show pictures and change picture properties, because of how powerful it is! The fact I can just run this script call $gameScreen.picture(1)._name = "sword1" and I can change what picture is being shown while keeping image rotation, scaling and X and Y values is awesome! But these script calls got me thinking...

Request: Is there a script call to change a picture's ID on the fly? I'm currently using $gameScreen.picture(11)._pictureId = 50 to change picture 11's ID to be 50 so that it will show above other pictures for a time; but while using this script call nothing happens, not even an error message telling me something is wrong with the script call. I know I could just show a new picture with ID 50 and delete picture 11, the only problem is that I'm showing an image based on a randomized variable, and by the time I need to switch picture 11 with picture 50 that variable has a new value, so it won't show the same picture.

Conclusion: If someone knows of a script call to be able to do this, that would be fantastic! If it's not possible, that's totally understandable. Just hoping that if script calls exist to change picture properties it would be possible to change a picture's ID.

Thank you in advance!
$gameScreen.picture(11)._pictureId = 50
You're assigning the pictureId property of picture 11 to 50? I don't know what that's supposed to do. It's still picture 11.
Where'd you get that reference? A Game_Picture object (which is what the picture() function returns) doesn't have any _pictureId member variable.

That's why you're not getting any error - you're just defining a new variable on the picture. That isn't wrong in JavaScript, but it also won't do anything in RPG Maker.

Unlike the IDs for your actors, items, events, etc., the ID for pictures isn't something defined on the picture. You didn't set it in the database anywhere - you choose it when you use the Show Picture command.

So the picture's ID is simply its index in the $gameScreen._pictures[] array. It's possible to use a chunk of JavaScript statements to store an array element's value, copy over it from another position in the array, then put that first one back.

You could do something like:
Code:
Game_Screen.prototype.picSwap = function(id1, id2)
{
    id1=this.realPictureId(id1);
    id2=this.realPictureId(id2);

    let tempPic=this._pictures[id1];
    this._pictures[id1]=this._pictures[id2];
    this._pictures[id2]=tempPic;
};

Copy that into a text editor, save as a *.js file, include as a plugin. Call it with $gameScreen.picSwap(x, y) where x and y are the two IDs you want to swap.

I haven't tried it out, let me know if it works or you run into any problems.
Spoiler: Original
You're assigning the pictureId property of picture 11 to 50? I don't know what that's suppised to do. Its still picture 11.
Thank you for the response, but that's the point of my posting this question. That's just the script call I'm trying to use to show an example. It is definitely wrong and doesn't work, but I figured I'd include it in case it would help let someone know what I'm trying to accomplish.

Spoiler: Original
Where'd you get that reference? A Game_Picture object (which is what the picture() function returns) doesn't have any _pictureId member variable.

That's why you're not getting any error - you're just defining a new variable on the picture. That isn't wrong in JavaScript, but it also won't do anything in RPG Maker.

Unlike the IDs for your actors, items, events, etc., the ID for pictures isn't something defined on the picture. You didn't set it in the database anywhere - you choose it when you use the Show Picture command.

So the picture's ID is simply its index in the $gameScreen._pictures[] array. It's possible to use a chunk of JavaScript statements to store an array element's value, copy over it from another position in the array, then put that first one back.

You could do something like:
Code:
Game_Screen.prototype.picSwap = function(id1, id2)
{
    id1=this.realPictureId(id1);
    id2=this.realPictureId(id2);

    let tempPic=this._pictures[id1];
    this._pictures[id1]=this._pictures[id2];
    this._pictures[id2]=tempPic;
};

Copy that into a text editor, save as a *.js file, include as a plugin. Call it with $gameScreen.picSwap(x, y) where x and y are the two IDs you want to swap.

I haven't tried it out, let me know if it works or you run into any problems.
I wasn't sure how close that script call would be to being accurate, and apparently it wasn't at all lol 😅 It's just a recycled script call that I use to change singular picture parameters without having to show a whole new picture.

But that plugin/script call seems to work beautifully! I'm able to swap any current picture with a new ID so I can show pictures above others without having to show a whole new picture, then I can just switch it back after. Thank you so much! You're amazing! 😍
You're welcome.

There's absolutely nothing wrong with asking, but it rarely makes sense to just try making things up in code. It can range from doing something you don't intend, to doing nothing, to crashing your game.

There's the pinned script call list you can look things up in:

And there's the MV library:
Spoiler: Original
You're welcome.

There's absolutely nothing wrong with asking, but it rarely makes sense to just try making things up in code. It can range from doing something you don't intend, to doing nothing, to crashing your game.

There's the pinned script call list you can look things up in:

And there's the MV library:
That's true. I like just poking around with JS because that's how I'm slowly learning it, but then I end up stumping myself because I get in way too deep sometimes 😅

Original thread: https://forums.rpgmakerweb.com/threads/change-a-pictures-id-with-js.157462/