Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

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

[rgss] 
# ================================================================
# Yet Another External Message Script
# Trebor777
# v 1.0
# 21/08/2009
# ================================================================
<span style="color:#000080; font-style:italic;">=begin
<span style="color:#000080; font-style:italic;">  How to use ?
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  1st, you need to load the messages in memory. The messages are stored
<span style="color:#000080; font-style:italic;">  in files, inside the Data/Text/ folder ( you need to create it )
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  The text file can be name as you like :)
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  So you load the file like this :
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  Text_Reader.load_file(filename)     !!!  filename doesn't contain the extension !!!
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  Then to display a message from this file, using the call_script command:
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  display_message(id , position, background, face_name, face_index)
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  You don't have to specify: position, background, face_name & index, by default:
<span style="color:#000080; font-style:italic;">    .position = 2, means bottom of the screen ( 0 = top, 1 = middle, 2 = bottom)
<span style="color:#000080; font-style:italic;">    .background = 1, means "dark", ( 0 = normal, 1 = dark(uses the messageback), 2 = transparent)
<span style="color:#000080; font-style:italic;">    .face_name = "", means no faceset is used. it's the name of the Faceset file.
<span style="color:#000080; font-style:italic;">    .face_index = 0, the position of the face in the faceset.
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">  FILE SPECIFICATION: very simple
<span style="color:#000080; font-style:italic;">    . file extension must be .txt.'
<span style="color:#000080; font-style:italic;">    . the messages are identified by numbers :),
<span style="color:#000080; font-style:italic;">    . messages can take as many lines as you wish, because RM is not that dumb, it'll
<span style="color:#000080; font-style:italic;">      display new "messages" when there are more than 4 lines.
<span style="color:#000080; font-style:italic;">  example:
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;">[0000]:Hey! How's it going?
<span style="color:#000080; font-style:italic;">Not too bad! You?
<span style="color:#000080; font-style:italic;">I'm cool.
<span style="color:#000080; font-style:italic;">Great so what's up?
<span style="color:#000080; font-style:italic;">[0001]: Not much actually, I'm working on a game called "SUPER GAME"
<span style="color:#000080; font-style:italic;">REeeaally ???  That's cool dude!
<span style="color:#000080; font-style:italic;">Yeah :) we're quite happy with it, though there is still loads to do!
<span style="color:#000080; font-style:italic;">[0002]: Well tell me when there will be a demo!
<span style="color:#000080; font-style:italic;">Sure I'll !
<span style="color:#000080; font-style:italic;">line 3
<span style="color:#000080; font-style:italic;">line 4
<span style="color:#000080; font-style:italic;">line 5
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;"> 
<span style="color:#000080; font-style:italic;"># ================================================================
<span style="color:#000080; font-style:italic;">=end
module Text_Reader
  @@messages = {}
  def self.load_file(file_id)
    if File.exist? "Data/Text/#{file_id}.txt"
      File.open("Data/Text/#{file_id}.txt",'rb'){ |file| Text_Reader.parse(file)}
    else
      p "I'm not crashing, but just to tell you: Text File \"#{file_id}.txt\" doesn't exist in the Data/Text/ folder."
    end
  end
  def self.parse(file)
    lines = file.readlines
    id = 0
    lines.each do |line|
      # Check if message ID is found
      id_ = line.scan(/\[(\d+)\]:/).flatten # Extract  "[0000]:", if no ID, returns []
      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.
      id = id_[0].to_i unless id_.empty? # Update current message ID if there is a new one
      if @@messages[id].nil? # New id ?
        @@messages[id] = [txt] # Add a new message array containing the 1st line
      else
        @@messages[id] << txt # Add the line to the current message array
      end
    end
  end
  def self.[](id)
    @@messages[id] || [] # If the message doesn't exist, return an empty array :) instead of nil
  end
end
 
class Game_Interpreter
  def display_message(id, position = 2, back = 1, face_name = "", face_index = 0)
    Text_Reader[id].each {|str| $game_message.texts << str }
    @message_waiting = true
    $game_message.background = back
    $game_message.position = position
    $game_message.face_name = face_name
    $game_message.face_index = face_index
    $game_message.main_proc = Proc.new { @message_waiting = false }
    return false
  end
end
 
[/rgss]

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 :

[rgss]Text_Reader.load_file(filename)   #  !!!  filename doesn't contain the extension !!!
[/rgss]

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

[rgss]display_message(id , position, background, face_name, face_index)
[/rgss]

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:
[rgss]display_message(2)
[/rgss]

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:


[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.
 
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. :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top