A simple question: RM MV have any call to check if a file exist?
Flie test?
Javascript/Plugin SupportYou could simply try to load it, like this:
var _loadFile = function(url) { var request = new XMLHttpRequest(); request.open('GET', url); request.onload = function() { /* File exists */ } request.onerror = function() { /* File doesn't exist */ } request.send();};Note, that this is asynchronous, so you'll need to wrap your code into a callback function, or split it and do the file test in Scene.create and the rest in Scene.start (and override Scene.isReady to wait for the test to finish).You can also change the request to be synchronous, but at least Chrome logs a warning and the game will be frozen during that time.
/edit: "Scene" refers to the concrete scene class, you want to use. Usually this is Scene_Boot, since it's meant to perform game initialization stuff.
var _loadFile = function(url) { var request = new XMLHttpRequest(); request.open('GET', url); request.onload = function() { /* File exists */ } request.onerror = function() { /* File doesn't exist */ } request.send();};Note, that this is asynchronous, so you'll need to wrap your code into a callback function, or split it and do the file test in Scene.create and the rest in Scene.start (and override Scene.isReady to wait for the test to finish).You can also change the request to be synchronous, but at least Chrome logs a warning and the game will be frozen during that time.
/edit: "Scene" refers to the concrete scene class, you want to use. Usually this is Scene_Boot, since it's meant to perform game initialization stuff.
Depends on what mode you're on. For the desktop client, you'll need to use Node's FS API.
For Web mode, you'll need to wrote a simple modification to the default function that gets data to send a HEAD request instead of a GET.
HEAD requests will only return the HTTP heaters for the path you sent for, so you'll have to check the status code. Any code below 400 is technically ok, anything above 400 is an error. The 400s themselves are client error (not authorized, file not found, etc), while the 500s are server errors (bad configuration, bad gateway, a generic "500 Server Error", etc.
For Web mode, you'll need to wrote a simple modification to the default function that gets data to send a HEAD request instead of a GET.
HEAD requests will only return the HTTP heaters for the path you sent for, so you'll have to check the status code. Any code below 400 is technically ok, anything above 400 is an error. The 400s themselves are client error (not authorized, file not found, etc), while the 500s are server errors (bad configuration, bad gateway, a generic "500 Server Error", etc.
In fact i already doing one here, but then I thought it would be kinda redundant if the maker had already one. Since the files i want check are the image files. i will just load the bitmap, and check if it's return an error.
Yeah, you should probably use HEAD, if you aren't going to use the file itself. If you want to load it, anyway, it's better to do it in one step, so you don't have to send 2 requests.
I wouldn't use Node's fs in a public plugin, since that would mean it can only be used in local games and will crash, when running on a server. Of course, you could switch depending on the environment, but AJAX calls on local files are fast and i don't see the reason to write the same stuff twice.
I wouldn't use Node's fs in a public plugin, since that would mean it can only be used in local games and will crash, when running on a server. Of course, you could switch depending on the environment, but AJAX calls on local files are fast and i don't see the reason to write the same stuff twice.
Due to this difference on how the maker handles files on desktop and web clients i'm trying on a different route similar on how i did on VX Ace.
Not sure, what you are trying to do, but MV handles files entirely different than Ace, mainly because you can't guarentee that game and resources exist on the same pc. Also, because of security reasons, you aren't allowed to scan a directory like you could in Ruby.
A sad thing to know =/. Then i will try your method, i just want to check if the file exist or not because i'm going to use sufixes to display some extra character poses and want to check if the pose with sufix exist and skip if not.
Original thread: https://forums.rpgmakerweb.com/threads/flie-test.52886/