Yet Another External Message Script

Yet Another External Message Script
Version: 1.0 : 21/08/2009
By: Trebor777

Introduction

Loads a txt file, and call the messages stored in it for your dialogs! Make your life easier for translations, and management.

Features
Aims to be super simple !

Screenshots
Well... it's for dialogs... so...
Demo
It's so simple you shouldn't need one.
Script

  1.  
  2. # ================================================================
  3. # Yet Another External Message Script
  4. # Trebor777
  5. # v 1.0
  6. # 21/08/2009
  7. # ================================================================
  8. =begin
  9.   How to use ?
  10.  
  11.   1st, you need to load the messages in memory. The messages are stored
  12.   in files, inside the Data/Text/ folder ( you need to create it )
  13.  
  14.   The text file can be name as you like :)
  15.  
  16.   So you load the file like this :
  17.  
  18.   Text_Reader.load_file(filename)     !!!  filename doesn't contain the extension !!!
  19.  
  20.   Then to display a message from this file, using the call_script command:
  21.  
  22.   display_message(id , position, background, face_name, face_index)
  23.  
  24.   You don't have to specify: position, background, face_name & index, by default:
  25.     .position = 2, means bottom of the screen ( 0 = top, 1 = middle, 2 = bottom)
  26.     .background = 1, means "dark", ( 0 = normal, 1 = dark(uses the messageback), 2 = transparent)
  27.     .face_name = "", means no faceset is used. it's the name of the Faceset file.
  28.     .face_index = 0, the position of the face in the faceset.
  29.  
  30.   FILE SPECIFICATION: very simple
  31.     . file extension must be .txt.'
  32.     . the messages are identified by numbers :),
  33.     . messages can take as many lines as you wish, because RM is not that dumb, it'll
  34.       display new "messages" when there are more than 4 lines.
  35.   example:
  36.  
  37.  
  38. [0000]:Hey! How's it going?
  39. Not too bad! You?
  40. I'm cool.
  41. Great so what's up?
  42. [0001]: Not much actually, I'm working on a game called "SUPER GAME"
  43. REeeaally ???  That's cool dude!
  44. Yeah :) we're quite happy with it, though there is still loads to do!
  45. [0002]: Well tell me when there will be a demo!
  46. Sure I'll !
  47. line 3
  48. line 4
  49. line 5
  50.  
  51.  
  52. # ================================================================
  53. =end
  54. module Text_Reader
  55.   @@messages = {}
  56.   def self.load_file(file_id)
  57.     if File.exist? "Data/Text/#{file_id}.txt"
  58.       File.open("Data/Text/#{file_id}.txt",'rb'){ |file| Text_Reader.parse(file)}
  59.     else
  60.       p "I'm not crashing, but just to tell you: Text File \"#{file_id}.txt\" doesn't exist in the Data/Text/ folder."
  61.     end
  62.   end
  63.   def self.parse(file)
  64.     lines = file.readlines
  65.     id = 0
  66.     lines.each do |line|
  67.       # Check if message ID is found
  68.       id_ = line.scan(/\[(\d+)\]:/).flatten # Extract  "[0000]:", if no ID, returns []
  69.       txt = line.split("[#{id_}]:").last.chomp # ID or not, the message will always be the last item in the split, ( last is the 1st, if size == 1 ). Removes the end of line character.
  70.       id = id_[0].to_i unless id_.empty? # Update current message ID if there is a new one
  71.       if @@messages[id].nil? # New id ?
  72.         @@messages[id] = [txt] # Add a new message array containing the 1st line
  73.       else
  74.         @@messages[id] << txt # Add the line to the current message array
  75.       end
  76.     end
  77.   end
  78.   def self.[](id)
  79.     @@messages[id] || [] # If the message doesn't exist, return an empty array :) instead of nil
  80.   end
  81. end
  82.  
  83. class Game_Interpreter
  84.   def display_message(id, position = 2, back = 1, face_name = "", face_index = 0)
  85.     Text_Reader[id].each {|str| $game_message.texts << str }
  86.     @message_waiting = true
  87.     $game_message.background = back
  88.     $game_message.position = position
  89.     $game_message.face_name = face_name
  90.     $game_message.face_index = face_index
  91.     $game_message.main_proc = Proc.new { @message_waiting = false }
  92.     return false
  93.   end
  94. end
  95.  
Expand to see the code.


Instructions

Read the header or read this:
How to use ?

1st, you need to load the messages in memory. The messages are stored in files, inside the Data/Text/ folder ( you need to create it )
The text file can be name as you like :)

So you load the file like this :

  1. Text_Reader.load_file(filename)   #  !!!  filename doesn't contain the extension !!!
Expand to see the code.


Then to display a message from this file, using the call_script command:

  1. display_message(id , position, background, face_name, face_index)
Expand to see the code.


You don't have to specify: position, background, face_name & index, by default:
  • position = 2, means bottom of the screen ( 0 = top, 1 = middle, 2 = top)
  • background = 1, means "dark", ( 0 = normal, 1 = dark(uses the messageback), 2 = transparent)
  • face_name = "", means no faceset is used. it's the name of the Faceset file.
  • face_index = 0, the position of the face in the faceset.
Means you can just write this:
  1. display_message(2)
Expand to see the code.


FILE SPECIFICATION: very simple
  • file extension must be .txt.'
  • the messages are identified by numbers :)
  • messages can take as many lines as you wish, because RM is not that dumb, it'll display new "messages" when there are more than 4 lines.
example:


Quote:
[0000]:Hey! How's it going?
Not too bad! You?
I'm cool.
Great so what's up?
[0001]: Not much actually, I'm working on a game called "SUPER GAME"
REeeaally ???  That's cool dude!
Yeah :) we're quite happy with it, though there is still loads to do!
[0002]: Well tell me when there will be a demo!
Sure I'll !
line 3
line 4
line 5


Be Aware for the length of each line !!! text editors are not limited unlike the event message !


FAQ
Does this work under XP ? Maybe I'm not sure, because of the way message are handled in XP. A XP version might come in the future, if heavily requested.

When I call twice display_message in the same "script" command, the 2nd message follows the 1st on the same page, is it a bug?? No it's not, it's voluntary for flexibility.
If you want two different messages to not be following each other directly on the same message box, simply call the second one , in a new "call script" command.

Compatibility

Should be compatible with everything :) I added a method in the Game Interpreter class.

Terms and Conditions

As usual, Commercial or Not, you can edit it, just don't delete my name :), You don't have to put me in the credits.
Hmm nice. Can help save time for those who already written their game's dialogue on a text document and just call it by a script call rather than re-typing everything again. Thanks for the script.
Exactly :) ^^ It's a tool to be used before the dialogs are made in game. :)

Though, this tool can be used for other purpose, as a scripter, can make use of it in other sections where text are needed. Like in a Menu, for example or in a CBS.
Hmm this can't extract the ones in the database right? :<
nope,
1st it's not an extractor. :)
2nd, the script doesn't edit the Vocab module....
although, it's possible to create a different version of the vocab module, that uses it. :)

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=66977