.txt Files Builder/Opener

MeowFace

Meow
Veteran
Joined
Feb 22, 2015
Messages
1,034
Reaction score
180
First Language
Meowish
Primarily Uses
Making this script for one of the request here.

It can be done using eventing alone too, but script makes the management easier.

For those interested in the eventing side, please check out that link instead.

Features:

[1] A simple way to create  .txt files using preset data in the script settings.

[2] A way to open those .txt file using its default program (eg. notepad/word)

What is it useful for:

Great if you want to prevent the lost of your readme.txt and recreate it when it's missing from the game directory. Or when you want to add additional game infos using .txt when the player reach certain stages in the game. eg. special password hints for new game+

As of the new update, it's now able to check if files exist on a script call, allowing those saved files to act as global save/flags for your game.

Compatibilities:

Using new methods in this script so a conflict is unlikely to happen unless another script uses the exact same new method names in their creation.

Terms of Use:

Feel free to use it in both commercial & non-commercial project

#==============================================================================# ■ Meow Face Text File Output#------------------------------------------------------------------------------# Create .txt files using the preset data in Settings#==============================================================================# How to Use:# [1] Put this script below Material and above Main# [2] Set up the datas in Settings Area below## Script Call:# txt_save("variable", "filename")## eg. txt_save("DOC1", "Filename.txt")#    will output DOC1 datas in settings to Filename.txt file## open_file("filename")## eg. open_file ("Filename.txt")#    will open Filename.txt file using its default program## check_file("filename")## eg. check_file ("Filename.txt")#    will check if Filename.txt file exist or not and return True/False# Use this script call in your conditional branches in the script box##==============================================================================module MeowFaceDoc # Do not Remove!#==============================================================================# Settings Area#==============================================================================#------------------------------------------------------------------------------# The folder you want the files to be created# Please use '.' for default game folder#------------------------------------------------------------------------------FOLDER = '.\Ending_Extra' #------------------------------------------------------------------------------# This is where you add your text documents# Add as many new @DOCX as you like (where X = the document number)# You can use "\n" to start a new line, or simply enter a new line below (see example below)#------------------------------------------------------------------------------@DOC1 = "=============Title of Doc=============Line 1Line 2Line 3Line 4Line 5"@DOC2 = "Line 1\nLine 2\nLine 3\nLine 4"@DOC3 = "Happy Kitty dancing in the hallAngry Mole rushing down the hole"#==============================================================================# End of Settings Area# Edit Anything Pass This Line at Your Own Risk!#==============================================================================endclass Game_Interpreter  def txt_save(data, filename)    @text = MeowFaceDoc.instance_variable_get("@#{data}")    Dir::mkdir(MeowFaceDoc::FOLDER) if !Dir.exists?(MeowFaceDoc::FOLDER)    @file = File.join(MeowFaceDoc::FOLDER,filename)    if !File.exist?(@file)      @CreateFile = File.open(@file, 'w')      @CreateFile.puts(@text)      @CreateFile.close      @text.clear    end  end  def open_file(filename)    @file = File.join(MeowFaceDoc::FOLDER,filename)    system %{cmd /c "start #{@file}"} if File.exist?(@file)  end  def check_file(filename)    @file = File.join(MeowFaceDoc::FOLDER,filename)    return true if File.exist?(@file) return false  endend
Update:

24/09/2015 - forgot to add a file check for opening file, it's fixed now

25/09/2015 - added a way to check if files exist
 
Last edited by a moderator:

MeowFace

Meow
Veteran
Joined
Feb 22, 2015
Messages
1,034
Reaction score
180
First Language
Meowish
Primarily Uses
Alternative version until web staff is able to fix the messed up code in the top post:

Code:
#==============================================================================
# ■ Meow Face Text File Output
#------------------------------------------------------------------------------
# Create .txt files using the preset data in Settings
#==============================================================================
# How to Use:
# [1] Put this script below Material and above Main
# [2] Set up the datas in Settings Area below
#
# Script Call:
# txt_save("variable", "filename")
#
# eg. txt_save("DOC1", "Filename.txt")
#    will output DOC1 datas in settings to Filename.txt file
#
# open_file ("filename")
#
# eg. open_file ("Filename.txt")
#    will open Filename.txt file using its default program
#
#==============================================================================
module MeowFaceDoc # Do not Remove!
#==============================================================================
# Settings Area
#==============================================================================
#------------------------------------------------------------------------------
# The folder you want the files to be created
#------------------------------------------------------------------------------
FOLDER = '.\Ending_Extra' 
#------------------------------------------------------------------------------
# This is where you add your text documents
# Add as many new @DOCX as you like (where X = the document number)
# You can use "\n" to start a new line, or simply enter a new line below (see example below)
#------------------------------------------------------------------------------
@DOC1 = "
=============
Title of Doc
=============
Line 1
Line 2
Line 3
Line 4
Line 5"

@DOC2 = "Line 1\nLine 2\nLine 3\nLine 4"

@DOC3 = "Happy Kitty dancing in the hall
Angry Mole rushing down the hole"

#==============================================================================
# End of Settings Area
# Edit Anything Pass This Line at Your Own Risk!
#==============================================================================
end
class Game_Interpreter
  def txt_save(data, filename)
    @text = MeowFaceDoc.instance_variable_get("@#{data}")
    Dir::mkdir(MeowFaceDoc::FOLDER) if !Dir.exists?(MeowFaceDoc::FOLDER)
    @file = File.join(MeowFaceDoc::FOLDER,filename)
    if !File.exist?(@file)
      @CreateFile = File.open(@file, 'w')
      @CreateFile.puts(@text)
      @CreateFile.close
      @text.clear
    end
  end
  def open_file (filename)
    @file = File.join(MeowFaceDoc::FOLDER,filename)
    system %{cmd /c "start #{@file}"} if File.exist?(@file)
  end
end
 

Mayli-Song

Villager
Member
Joined
Dec 5, 2012
Messages
6
Reaction score
0
First Language
English
Primarily Uses
Sorry if this is an obvious question, but I'm still figuring out code. How would you use this to check if a file exists? Like if I wanted to make a conditional branch where the dialogue will change depending on whether a file exists, how would I do that?
 

Taishiro13

Villager
Member
Joined
Jul 11, 2018
Messages
5
Reaction score
0
First Language
Filipino
Primarily Uses
RMVXA
it gives me the error:

Script " line 22: SyntaxError occured.

unexpected tCONSTANT, expecting $end
module MeowFaceDoc
 

Kes

Global Moderators
Global Mod
Joined
Aug 3, 2012
Messages
21,611
Reaction score
10,924
First Language
English
Primarily Uses
RMVXA
@Taishiro13 Check that you have copied the full script, including all the "end"s at the end.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,230
Reaction score
6,771
First Language
German
Primarily Uses
RMMV
Script " line 22: SyntaxError
1) script '' means that you have not named the script slot, otherwise it would read something like script 'scriptname'.
Please make sure to always name a slot as soon as you enter a script into it, otherwise bughunting is difficult.

2) that Syntax error could also be the result of an error while editing the script.
You have to edit the script for it to work correctly, and if you made a mistake with that edit it could also cause such an error.
So that have you changed from the default script?
 

Taishiro13

Villager
Member
Joined
Jul 11, 2018
Messages
5
Reaction score
0
First Language
Filipino
Primarily Uses
RMVXA
I was able to do this using event without the script. Thanks tho.
 

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

Latest Threads

Latest Profile Posts

putting a puzzle in my game that BSODs the player's computer if they complete it
I finally got a book out the door after seven years of nothing \^-^/ Now if I can get a game out the door too, that'd be great...
MY GAME IS NOW OFFICIALLY RELEASED!!
*FurAffinity is down*
*Sets house on fire*
This is fine.

Forum statistics

Threads
94,363
Messages
920,262
Members
124,126
Latest member
TookMyRole
Top