ozu_File – Create and manipulate files from within the game itself!

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
ozu_File 1.2
by ozubon

Introduction

Using Node.js' file system module can be a hassle. Getting it to work both in playtest and after deployment seems to be something people are having trouble it. This aims to give some easy to use functions as tools for manipulating the game folder's files using Node.js – both for people who've tried implementing the .fs module and failed and for anyone with basic script call knowledge who wants to play with files.

Does not work on mobile!

Features
This plugin allows you to do things with your game files and folders from within the game itself.
  • file.exist will check whether a file exists or not
  • file.write will write or overwrite a file with the text you enter
  • file.append will add text to an already existing file
  • file.read will read a file and output its contents as text
  • file.rename will rename a file to the filename you enter
  • file.erase will permanently delete a file
How to use
file.exist
Checks if a file in your game folder exists or not.
Intended for the conditional branch script box.
Code:
file.exist("path", "file.type")
"" for path means the main game folder, "" for file checks if folder exists

These all return TRUE:
Code:
file.exist("", "index.html")

file.exist("data", "")

file.exist("img/system", "Window.png")

This returns FALSE unless it exists:
Code:
file.exist("asdf/gh", "jkl.txt")

Screenshot example:
file.write
Writes a new file with the desired data.
Intended for script calls.
Code:
file.write("path", "file.type", "stuff")
"" for path means the main game folder, the rest is required.

Some examples:
Code:
file.write("", "tanoshindekudasai.txt", "Arigato gozaimasu")
Code:
file.write("data", "test.json", "Can it write to JSON?")

Screenshot example:
filewrite.png
file.append
Same as file.write but writes to the end of an existing file instead of overwriting it.
Intended for script calls.
Code:
file.append("path", "file.type", "new stuff")
"" for path means the main game folder, the rest is required.

Some examples:
Code:
file.append("", "tanoshindekudasai.txt", "!!!")
Code:
file.append("data", "test.json", " Yes.")

Screenshot example:
fileappend.png
file.read
Reads a file and outputs a string of what's in it.
Intended for conditional branches and setting variables.
Code:
file.read("path", "file.type")
"" for path means the main game folder, the rest is required.

This will return TRUE in a conditional branch (if tanoshindekudasai.txt is exactly "Arigato gozaimasu!!!"):
Code:
file.read("", "tanoshindekudasai.txt") === "Arigato gozaimasu!!!"

Using Control Variables, set a variable to
Code:
file.read("", "tanoshindekudasai.txt")
and the variable will be set to "Arigato gozaimasu!!!" or whatever tanoshindekudasai.txt contains.


Screenshot example:
fileread.png
file.rename
Renames a file, careful not to rename important files.
Intended for script calls.
Code:
file.rename("path", "file.type" "new name.type")
"" for path means the main game folder, the rest is required.

Some examples:
Code:
file.rename("", "tanoshindekudasai.txt", "ieie.txt")
Code:
file.rename("data", "test.json", "johnromero.json")

Screenshot example:
filerename.png
file.erase
Do not use this one unless you know what you're doing!
Permanently deletes a file, be VERY careful not to erase important files.
Intended for script calls.
Code:
file.erase("path", "file.type")
"" for path means the main game folder, the rest is required.

Some examples:
Code:
file.erase("", "ieie.txt")
Code:
file.erase("data", "johnromero.json")

Screenshot example:
filereerase.png

Terms of use
You don't have to credit me but I'd appreciate it!
For commercial use, you gotta credit me!

Plugin
Right-click link -> Save As

Credit
ozubon
Kino for this guide
 

Attachments

Last edited:
Joined
Feb 18, 2015
Messages
519
Reaction score
263
First Language
English
Primarily Uses
RMMV
I've tried using this, but it doesn't seem to be creating a file when I use the file.write command. I also tried creating the file and seeing if it would edit the file, and that also didn't work. In addition, when I ran a check for if the file I'd created exists, it always acts as if the file doesn't exist (even though it is in the place I told it to look).
Since I tried this plugin out in a project I use for trying out small plugins and random game mechanics, I turned off all the other plugins in that project. Running the file.write command gave this error:
1586853840402.png
(The command I used was file.write("", "test.txt", "This is a text file"), since your guide says that "" means the game folder. Trying to specify the data folder resulted in the error below instead.)
1586853940232.png
This could be a really cool plugin, but I can't seem to get it to work - it keeps wanting to put files directly to my C: drive rather than the game folder.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
Strange, this is run of the mill Node.js fs. Which version of the maker are you running, where do you store your game and which operating system are you using? :unsure:

Edit: Ok but no it's not run of the mill Node.js fs, that's the whole point of this plugin lmao. Never mind my brain fart.
 
Last edited:
Joined
Feb 18, 2015
Messages
519
Reaction score
263
First Language
English
Primarily Uses
RMMV
I'm on 1.6.2, my game is in Documents as per Steam/MV default, and I'm on Win10.
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
Well I'll be a monkey's uncle...
My bad, should be working now!

Version 1.1
  • Fixed bug with code not finding the relative path

 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
Version 1.2
  • Added file.append, a function similar to write but can add text to the end of a file instead of overwriting the file
  • Added compability for older versions of MV
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
684
Reaction score
212
First Language
Vietnamese
Primarily Uses
RMMV
Thank you for this. It is a good plugin to manipulate the player's file. I just want to find a way to delete player's save if they do some certain things and this serves my purpose perfectly.
 

TomorrowAvenger

Villager
Member
Joined
Oct 8, 2018
Messages
10
Reaction score
1
First Language
Italian
Primarily Uses
RMMV
Thank you (for the second time lmao) for this plugin! It works perfectly and gives a lot of possibilities! I feel powerful over the game's files now xD
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
thank you both for your comments <3
 

_Shadow_

Tech Magician Level:
Moderator
Joined
Mar 2, 2014
Messages
4,012
Reaction score
2,621
First Language
Greek
Primarily Uses
RMMV
Neat! Just a few questions ad suggestions:

Why did you used the not operator? Is there a reason behind it? I mean you can return 1 instead of returning !0 right?

A good idea would be turning encoding to a parameter. By default set it to utf-8 but if someone wants another for whatever reason, they should have the option to play with it. While hadcoded change can solve this issue, if they need to manipulate files with different encoding that would be a problem.

file.read will read a file and output its contents as text
This needs to return a set of lines from a file.
But despite that, the plugin is a great idea. After all you are still enhancing this as I see!
 

ozubon

surströmming?
Veteran
Joined
Oct 16, 2018
Messages
178
Reaction score
167
First Language
English
Primarily Uses
RMMV
!0 was for, as you say, "the lulz"

You're right, I should definitely add an option to change encoding. Also next update remove the completely superflous "folder", "file" sectioning and just go with "folder/file".

Maybe I'll switch !0 to !!Infinity
 

Jatopian

Veteran
Veteran
Joined
Jul 5, 2015
Messages
52
Reaction score
14
First Language
English
Primarily Uses
Does not work on mobile!
Hello, could I ask for some details about this?

I am not very familiar with file handling in node.js, but I am trying to handle the case of an image resource file (like a faceset) not being present as expected. Is that something that's just broadly impossible on mobile for some reason, or is it just that I should try something besides your plugin like Kino's tutorial, or could I just avoid using certain features of your plugin that don't work on mobile?
 

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

Latest Threads

Latest Posts

Latest Profile Posts

When you're lost out therrrrre and you're alllll alone, ahwahwah waitin, to carry you hooooommmme, uhhheverywhere you look! (someone hit me with those backing vocals)
X.X cant focus... too many thing want do... help!
Day 2 of teaching MV, student can move cat across the map.
Got inspired and started writing a simple tower defence battle system last night :o
Good news! I have located an amazing 3D website called SketchFab that has rotatable renderings of famous statues!

Forum statistics

Threads
100,524
Messages
976,782
Members
132,080
Latest member
nwr
Top