Check if file exists in the installation folder

TomorrowAvenger

Villager
Member
Joined
Oct 8, 2018
Messages
10
Reaction score
1
First Language
Italian
Primarily Uses
RMMV
I'm really sorry if I post this in the wrong section: I don't know this forum very well.
I've been desperatly searching for some condition, or plugin, or script call to check if a certain external file that I put in the game's folder exists or not: if the player deletes it, the event will react differently.

I think you already solved this problem in another thread (https://forums.rpgmakerweb.com/index.php?threads/check-if-local-file-exists.50866/) , but I can't make these commands work...
Maybe for you, who know surely more about script calls than me, will be simple to answer my request ^^'
(sorry if I have bad english, just an ITA in a rush :'))
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,693
Reaction score
554
First Language
Dutch
Primarily Uses
RMMV
it depends in what path and for what file you want to see if it exist or not.
because it seems to work correctly though
 

TomorrowAvenger

Villager
Member
Joined
Oct 8, 2018
Messages
10
Reaction score
1
First Language
Italian
Primarily Uses
RMMV
it depends in what path and for what file you want to see if it exist or not.
because it seems to work correctly though
Oh... Maybe I wrote the call badly :(
If that doesn't bother you, can you send a screen of the event page?

To answer the first question: the path is the normal installation folder of the game, the one with the project and "index".
The file is a normal .txt.
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,693
Reaction score
554
First Language
Dutch
Primarily Uses
RMMV
it depends if the "install" means in stall the game or the rpg mv main installation.
while I dont use the install, most ppl can change the installation of the project,
and have it on the D drive instead of the C drive.

and if its a deployment game with all files, its mostly in the root where they unpack
the rar/zip package and click the game.exe (unless game is changed to the name
of the game itself. so the directory can be different by than as well.

in case of teh 2nd alternate path ( D-drive) or C drive -> desktop, the code
might be slightly different as well, and probably with else if and else brance
to check those.

its better to have it check the main folder for that file what you need to look for.
and if it needs to throw an error or not if the file does not exist.

but than again, changing that code correct to the file is also out of reach of
my js knowledge while im still learning js in overal and get the full meanings.
 

TomorrowAvenger

Villager
Member
Joined
Oct 8, 2018
Messages
10
Reaction score
1
First Language
Italian
Primarily Uses
RMMV
it depends if the "install" means in stall the game or the rpg mv main installation.
while I dont use the install, most ppl can change the installation of the project,
and have it on the D drive instead of the C drive.

and if its a deployment game with all files, its mostly in the root where they unpack
the rar/zip package and click the game.exe (unless game is changed to the name
of the game itself. so the directory can be different by than as well.

in case of teh 2nd alternate path ( D-drive) or C drive -> desktop, the code
might be slightly different as well, and probably with else if and else brance
to check those.

its better to have it check the main folder for that file what you need to look for.
and if it needs to throw an error or not if the file does not exist.

but than again, changing that code correct to the file is also out of reach of
my js knowledge while im still learning js in overal and get the full meanings.
Thank you so much for the explanation, but I think my problem is even easier to fix ^^. Maybe I was bad at explaining my situation.

forum.JPG
I want to check if "test.txt" is in this folder.
I'll make an example of what I want to do:

-If "test" isn't in this folder, for example, if you click a guy (with the condition I want it to have) he will say "Hey, you don't have that gnarly text file, we can't be friends" (?)

-You do the event that creates "test" in the folder: this procedure already works in the project ^^

-"test" is in this folder now. The guy will say, if you click him, "Yay, you have the text file! We can be friends now"

I really wanted to use this script call:

Code:
var fs = require('fs');if(fs.existsSync("index.html")) {  // The file exists, do stuff.} else {  // The file does not exist, do other stuff.}
But it doesn't work for me.
And so I asked myself: did I write the script call badly? How should I use it? There's another method to do what I want to do?
So... Yeah, I just wanted to ask how to use this call (I'm pretty dumb with script calls, like I said multiple times: maybe I wrote it badly), if there isn't any easier way to do this.
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,693
Reaction score
554
First Language
Dutch
Primarily Uses
RMMV
as for conditional brance scriptcall, beats me,
but in your case, "index.html" can be changed to "text.txt" (while you want to check this file.

{ //code here if its exist } no idea how to code that part
else { \\ code here } if it doesn't exist, but idk if there is a ttypical scriptcall.

I can try to search around, but the path of the fs must exist or it cant really check the root
of the gamefile for the specific txt file.

I try to search around for the exact js and or scriptcall to use unless someone with js coding aswer you before me.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
164
First Language
English
Primarily Uses
RMMV
Edit: I decided to make it a full fletched plugin, it can be found here:

Original post:
Using fs.existsSync() without a defined path will not work in dev mode, and then that path won't work when you deploy the game.
For your comfort you need a function that can establish a relative path!

Based on this guide I made this itty bitty plugin you can use.
Simply use
Code:
ozuExist.file("", "test.txt")
in a conditional branch's script box to check if that one exists, or if it was in the characters folder it would be:
Code:
ozuExist.file("img/characters", "test.txt")

"" means main folder, otherwise you specify, you get it?

Download the plugin here:

Broken code, I unattached the plugin.
Go to the full, supported (and working) plugin.
 
Last edited:

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,693
Reaction score
554
First Language
Dutch
Primarily Uses
RMMV
this can be really helpfull for dev's that want to use it. nice job
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
164
First Language
English
Primarily Uses
RMMV
Thank you but the original plugin I posted in this thread contained a bad bug, so now I kindly refer to the full plugin :')
 

TomorrowAvenger

Villager
Member
Joined
Oct 8, 2018
Messages
10
Reaction score
1
First Language
Italian
Primarily Uses
RMMV
Edit: I decided to make it a full fletched plugin, it can be found here:

Original post:
Using fs.existsSync() without a defined path will not work in dev mode, and then that path won't work when you deploy the game.
For your comfort you need a function that can establish a relative path!

Based on this guide I made this itty bitty plugin you can use.
Simply use
Code:
ozuExist.file("", "test.txt")
in a conditional branch's script box to check if that one exists, or if it was in the characters folder it would be:
Code:
ozuExist.file("img/characters", "test.txt")

"" means main folder, otherwise you specify, you get it?

Download the plugin here:

Broken code, I unattached the plugin.
Go to the full, supported (and working) plugin.
Thank you so much!! :D
I will test it when I'll have time!
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
164
First Language
English
Primarily Uses
RMMV
It's all good, bump the plugin thread if you like it :p
 

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

Latest Threads

Latest Profile Posts

Ahh, end of the day stinky feet, fresh out of the boots. Smells like a job well done. Seriously, I have to rinse my feet when I get home, or it's not fair to my wife.
Stream will be live shortly with some pixel art! Feel free to drop by!

Can't believe I forgot to put an image of my drawing pad! It looks kinda like this, maybe I'll get a better pic tomorrow...
Backup tip: If you don't want to back up your whole project every day, at least back up everything *except* your Image and Audio folders, which you can do weekly/as needed/etc.
The final version of our game is already available both in English and Spanish! ^___^
Can't believe this day has finally come... T_T

Forum statistics

Threads
97,822
Messages
947,184
Members
129,037
Latest member
Luciamandela
Top