Loading Screen Script? + 'drawImage' Error

I'm wondering id there are any existing scripts that let you do anything with the loading screen. For example, every time the game loads a different picture is selected for the loading screen. Is this easily doable/has it already been done?


I thought of replacing this line in rpg_managers.js...


Graphics.setLoadingImage('img/system/Loading.png');


With this, since I now have 3 image files called 'Loading1.png', 'Loading2.png', and 'Loading3png'...


Graphics.setLoadingImage('Loading' + Math.ceil(Math.random() * 3) + '.png');


I'm no expert at Javascript so it could be really flawed...I got an error as a result.

Code:
Failed to execute 'drawImage' on 'CanvasRenderingContext2D': The HTMLImageElement provided is in the 'broken' state

Then I tried running it as a common event after the first map loads, and now...well it gives me the exact same error.
You are posting under javascript, so I assume you are running MV, not Ace? Asking because your profile says you are primarily using Ace. Anyways, the first line you put:


Graphics.setLoadingImage('img/system/Loading.png');


looks like it is calling a specific image - "Loading.png" through the pathway "img/system". I would suggest first that you find this folder system, and import your graphics to that specific pathway. Next, try just switching the file name from "Loading.png" to "Loading1.png" (or one of your other file names) to see if it still works. Next, (I'm not very familiar with the method system of Javascript, but have used C++ in the past) I would assume you would make an array of all three images and instead of calling the specific file name, you would replace it with a call to the array that picks a random image from that array. Something like this:


var item = items[Math.floor(Math.random()*items.length)];




So make a var called "loading", for example:


var loading = [ "Loading1.png", "Loading2.png", "Loading3.png"];


(I'm pretty sure you will have to somehow define these 3 pictures, but as said I'm not too familiar with Javascript, atm)


I think next you place the random line:


var loading = loading[Math.floor(Math.random()*loading.length)];


Then when you go to call the image, I think it should read something like:


Graphics.setLoadingImage(loading);


Hope this at least sets you on the right course.
You are posting under javascript, so I assume you are running MV, not Ace? Asking because your profile says you are primarily using Ace. Anyways, the first line you put:


Graphics.setLoadingImage('img/system/Loading.png');


looks like it is calling a specific image - "Loading.png" through the pathway "img/system". I would suggest first that you find this folder system, and import your graphics to that specific pathway. Next, try just switching the file name from "Loading.png" to "Loading1.png" (or one of your other file names) to see if it still works. Next, (I'm not very familiar with the method system of Javascript, but have used C++ in the past) I would assume you would make an array of all three images and instead of calling the specific file name, you would replace it with a call to the array that picks a random image from that array. Something like this:



var item = items[Math.floor(Math.random()*items.length)];




So make a var called "loading", for example:


var loading = [ "Loading1.png", "Loading2.png", "Loading3.png"];


(I'm pretty sure you will have to somehow define these 3 pictures, but as said I'm not too familiar with Javascript, atm)


I think next you place the random line:


var loading = loading[Math.floor(Math.random()*loading.length)];


Then when you go to call the image, I think it should read something like:


Graphics.setLoadingImage(loading);


Hope this at least sets you on the right course.

I tried this along with SEVERAL variations of this as well and got the exact same error. It almost seems like JavaScript is somehow working differently within RPG Maker MV...unless there's something I'm just missing.
Ah wait I figured it out. I was first not defining image paths clearly...then tried defining them as variables like this


var Loading1 = ('img/system/Loading1');


The solution was much simpler, though.


Graphics.setLoadingImage('img/system/Loading' + Math.ceil(Math.random() * 3) + '.png');


Don't know why I didn't try that from the start...thank you for the reply! Your insight did help me realize my msitake.
im getting this error please help me.. What is the main cause for it?

Original thread: https://forums.rpgmakerweb.com/threads/loading-screen-script-drawimage-error.61877/