Jump to content

Recommended Posts

Export Messages to File

Version: 1.0
Author: GubiD
Date: Feb 25, 2013

 

Description
This script grants you the ability to export the message text from every single message box in your game.  This is helpful for many reasons.  

  1. Spell check
  2. Grammar check
  3. Does it flow well?


Screenshots
There is nothing to really screenshot??

Instructions

  • Place this script in your project anywhere above main. 
  • At the top of the script, set ENABLED = true 
  • At next game launch all the messages within will be exported to MAP folders with EVENT.txt files for each event with messaging.  If no message text was found, then no file is created.

Script

#------------------------------------------------------------------
# Object
#------------------------------------------------------------------
class Object
  def string?
    return false
  end
end
#-----------------------------------------------------------------
# String
#------------------------------------------------------------------
class String
  def string?
    true
  end
end
#------------------------------------------------------------------
module Export_Messages
  #------------------------------------------------------------------
  # Enabled - When true, data will export.  Otherwise no.
  #------------------------------------------------------------------
  ENABLED = false
  
  #------------------------------------------------------------------
  # Maps File - File in which contains the map information
  #------------------------------------------------------------------
  MapsFile = "./Data/MapInfos.rvdata2"
  
  #------------------------------------------------------------------
  # Event Messages Folder
  #------------------------------------------------------------------
  EVENT_MESSAGES_FOLDER = "./Messages/"
  
  #------------------------------------------------------------------
  # Make Folder Name (from map ID and MAP)
  #------------------------------------------------------------------
  def self.make_folder_name(id, map)
    return sprintf("%03d_%s", id, map.name);
  end
  #------------------------------------------------------------------
  # Export Messages
  #------------------------------------------------------------------
  # This exports all the events messaging in the game on every map
  #------------------------------------------------------------------
  def self.export_messages
    maps = load_data(MapsFile)
    if !Dir.exist?(EVENT_MESSAGES_FOLDER)
      Dir.mkdir(EVENT_MESSAGES_FOLDER)
    end
    for id in 1...maps.size+1
      mapFile = sprintf("Data/Map%03d.rvdata2", id)
      mapInfo = maps[id]
      map = load_data(mapFile) rescue next
      foldername = EVENT_MESSAGES_FOLDER + make_folder_name(id, mapInfo)
      if !Dir.exist?(foldername)
        Dir.mkdir(foldername)
      end
      for event_id in map.events.keys
        event = map.events[event_id]
        for i in 0...event.pages.size
          filename = sprintf("%s/%03d_%s_%02d.txt", foldername, event_id, event.name, i+1)
          if File.exist?(filename)
            File.delete(filename)
          end
          file = File.new(filename, 'a') #open file in append mode
          file.write(sprintf("%03d %s Page_%02d", event_id, event.name, i+1))
          write_linebreak(file)
          
          page = event.pages
          
          event_string_data = build_event_string_data(page)
          
          file.write(event_string_data)
          file.close
          
          if event_string_data == ""
            File.delete(filename)
          end
        end
        
      end
    end
    print "Finished Exporting messages to file\n"
  end
  #------------------------------------------------------------------
  # Construct message string data
  #------------------------------------------------------------------
  def self.build_event_string_data(page)
    save_string = []
    @index = 0
    #------------------------------------------------------------------
    # Walk list and check each item.  
    # Since choices already sort items for us, no additional sort is needed. 
    #------------------------------------------------------------------
    while page.list[@index] != nil
      event_data = page.list[@index]
      indent = "\t " * event_data.indent
      if ([101, 401].include?(event_data.code))
        s = event_data.parameters[0]
        save_string << indent + "[MESSAGE]" + s unless s == ""
      elsif [402].include?(event_data.code)
        for s in event_data.parameters
          save_string << indent + "[CHOICE]" + s if s.string?
        end
      elsif [404].include?(event_data.code)
        save_string << indent + "[END_CHOICE]"
      end
      @index += 1
    end
    return save_string.join("\n")
  end
  #------------------------------------------------------------------
  # Write Linebreak
  #------------------------------------------------------------------
  def self.write_linebreak(file)
    file.write("\r\n")
  end
  if ENABLED
    export_messages
  end

end  




Credit

  • No credit is needed unless you want to.


Thanks

  • Feldherren for requesting it


Support
Post in this thread or PM me.


Known Compatibility Issues
I am unaware of any scripts it doesn't work with; if you find any, post in this thread.

Demo
N/A


Author's Notes
I created this script because Feldherren requested the ability to dump all messages to file quickly.  Not only for spell checking but other checks as well.  


Terms of Use
Non-Commercial or Commercial free.  Have fun and enjoy it.  

 
Edited by GubiD

Share this post


Link to post
Share on other sites

Wow, I would have never even thought of such a thing. Brilliant, simply brilliant. :D
I will surely use this for checking spelling & grammar. B)

Share this post


Link to post
Share on other sites

Possibly because there is a part missing. Line 69

          page = event.pages

page = event.pages[i]


 

Just tried it myself. Works great.

Edited by roninator2
Needed to code box

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×