RMMV How to write a plugin which checks if an image is part of a list?

EthanFox

Veteran
Veteran
Joined
Oct 15, 2018
Messages
517
Reaction score
347
First Language
English
Primarily Uses
RMMV
EDIT: Thread was - Is it possible to test for a positive loadPicture() first?"

Now it's something a bit different; see third post

================================


For instance, take the statement:

var img = ImageManager.loadPicture('blah');

In MV, if the game tries to load a picture that does not exist, the error will appear onscreen (with a retry button).

Is it possible to create an IF statement where it first checks if an image exists, then if it exists, it loads, and if it doesn't exist, the game does something else?

Apologies if this is something quite basic; I'm not much of a scripter.
 
Last edited:

theartofme

Veteran
Veteran
Joined
Feb 21, 2019
Messages
32
Reaction score
43
First Language
English
Primarily Uses
RMMV
You can use ImageManager.requestPicture() (or any of the ImageManager.request...() functions). It won't show the error screen, it will only try once (the regular load... functions will retry several times before showing the error), and you can use the isError() function to see if there was an error or not; if you have:

var img = ImageManager.loadPicture('blah');

Then at some later time (not immediately, because the request is async - it makes a note to go and load the picture later after running your code) you can do:

if (img.isError()) { ... }

To handle your error case. Unfortunately bitmaps don't have a callback for the error case, so you just have to keep checking your image (inside an update() function somewhere) to see if either isReady() or isError() become true. You could add an error callback yourself:
JavaScript:
var img = ImageManager.loadPicture('blah');
img._image.removeEventListener('error', img._errorListener);
img._image.addEventListener('error', img._errorListener = function() {
    // there was an error loading this image, do whatever you need here
});
img.addLoadListener(function() {
    // the image loaded successfully, use it here
})

But that's getting kinda hacky IMO, hopefully someone has a better idea.
 

EthanFox

Veteran
Veteran
Joined
Oct 15, 2018
Messages
517
Reaction score
347
First Language
English
Primarily Uses
RMMV
Thanks @theartofme ; I think the basic thing I wanted to do is probably out of the question, so I want to try another way.

To give a bit of background, I'm modifying Galv's bust plugin (I've spoken to Galv, that's all cool).

At present, the plugin works as follows:

When the bust functionality is enabled, when the game would bring up a face image in a text box, it references a different image for the bust. So, if you want Actor 1's top left face, the plugin will reference an image called Actor1_1_bust.png, and display that bust. But, if Actor1_1_bust.png doesn't exist, it will display an error.

I would like to change it so that there is a list of face images in the plugin, so in the above example, this list might contain Actor1.png.

When the game goes to load a bust, it first checks if the face image is in the list (IF Actor1.png is in the list...), and then it only displays the bust if that resolves to TRUE; if FALSE (i.e. Actor1.png is not in the list) then it would just display the regular face image, not a bust.

(to explain; the reason for this is that I already have a game where I use face images, and that should remain as-is - but I want the ability to replace major speaking character faces with busts without making extensive changes to my actual game).

I think what I need to know are two things:

  • How, in an MV plugin, do I specify that I want to create a list of images via the plugin menu?
  • Is there an easy way in the IF statement to say "IF the desired image == any element in the list of images"
I can probably figure out the rest through trial and error.

Anyway, if anyone can help me with this, it'd be much appreciated.
 

Attachments

  • 1610978107381.png
    1610978107381.png
    16.9 KB · Views: 3
Last edited:

EthanFox

Veteran
Veteran
Joined
Oct 15, 2018
Messages
517
Reaction score
347
First Language
English
Primarily Uses
RMMV
Just an update, I suggest closing this thread - I'm going to need to pay a scripter to help out, as it's a more complex problem than I originally realised.
 

theartofme

Veteran
Veteran
Joined
Feb 21, 2019
Messages
32
Reaction score
43
First Language
English
Primarily Uses
RMMV
You needn't close the thread, those problems are much simpler than in your original question!

To create a plugin parameter that's a list of image names:
Code:
@param allowList
@type file[]
@dir img/pictures
This goes with the rest of the plugin parameters, you should be able to find them. You should also be able to find where they're set near the top of the plugin and add something like:
Code:
Galv.MB.allowList = JSON.parse(PluginManager.parameters('Galv_MessageBusts')["allowList"]);

Finally, to check an image is in that list, just:
Code:
if (Galv.MB.allowList.indexOf(imageName) !== -1) {
    // image is in the list, you can use it
}
 

Latest Threads

Latest Posts

Latest Profile Posts

Kind of relieved that I had medibang installed when I need to edit Sprite I was about to download gimp but I remember I had medibang installed lol
Voting for the first round of the Map Madness Tournament is now live! Vote for your favorite in each matchup!

Finally started working on Grim Trigger episode 2 today :LZScat: it's half comic/half visual novel!

GfY3Rwj.png
Is it interesting to get more backstory on villains? A key moment in their past, their childhood, or maybe something that shows they've always been that way? To see or not to see?
"Everything tastes like chicken until it's chicken, then it doesn't taste like chicken."
Context: chicken samosas do not taste like chicken. I thought it was veggie samosas.
Just another ordinary evening.

Forum statistics

Threads
110,366
Messages
1,052,632
Members
143,401
Latest member
Nazgramaria
Top