How to monitor for missing database file?

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
I'm working on a plugin that will create a new json file in the data folder.  After creation it will be loaded along with all the database files.


My problem is that until the code in the plugin is run to populate and save this file, it won't exist.


Is there a way I can override this part of the DataManager.loadDataFile so if my particular file doesn't exist, it just creates an empty object, without having to rewrite that function?


xhr.onerror = function() {
DataManager._errorUrl = DataManager._errorUrl || url;
};


I am trying to avoid plugin users having to create that file manually.


Edit: I suppose I could just do a fs.existsSync test to see if the file is there, and create it if it isn't, rather than worrying about handling a missing file when loading the database.
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
Edit: I suppose I could just do a fs.existsSync test to see if the file is there, and create it if it isn't, rather than worrying about handling a missing file when loading the database.
That will only work in nw.js, but you also won't be able to create the file without nw.js.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
The file will only ever be created when running in test mode.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
Ah, right. Then existsSync is a good way to do it.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
different question, but for same plugin ...


Can I do something like this, and only have the additional code run when in test mode?


(function() {

// code in this section will only be run when play testing
if (Utils.isOptionValid('test')) {

var _Game_Interpreter_clear = Game_Interpreter.prototype.clear;
Game_Interpreter.prototype.clear = function() {
_Game_Interpreter_clear.call(this);
this._myVar = null;
};

};


// code in this section will always be run
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);

// do my stuff here
};
})();


What I'm after is a section of code that would only be run when in test mode, and another section that would be run at all times.  So this._myVar would only be created and set to null when play testing (and would only ever be used in that Utils.isOptionValid('test') block.


Just doing some testing with this in an event:

Code:
Script: if (this._myVar === undefined) {
          $gameVariables.setValue(1, "undefined");
        } else if (this._myVar === null) {
          $gameVariables.setValue(1, "null");
        }
Text: None, Window, Bottom
      \v[1]
it shows "null" in the text box whether I test play or play from a deployed exe.


So maybe not?
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
Yup, when not in test mode, your version of the clear method simply won't exist. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
why does my event always set the variable to 'null' then and not 'undefined'?  I'd expect, if my version of the clear method doesn't get run, this._myVar would be undefined rather than null?
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,546
Reaction score
3,717
First Language
Java's Crypt
Primarily Uses
RMMZ
Are you sure you're not setting null to that variable anywhere else? And that your deployed version doesn't have test mode activated?


(If you can open the console in the deployed version, it has the test mode enabled)
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,111
Reaction score
13,715
First Language
English
Primarily Uses
RMMV
Yep.  That line was the only place where the variable was used.  I'd only just started building the script, and that's the first thing I wanted to test.  What you see there is the entire plugin I was testing at the time - I didn't even have anything in the plugin function.


I couldn't access the console in the deployed version, which is why I had to resort to using a script call to check the value and showing the results in a text command (couldn't use console.log because I couldn't bring up the console).
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,051
Messages
1,018,549
Members
137,836
Latest member
T62352536256t362
Top