Message from File ScriptVersion: v1r
By: Phoenixia
Introduction
This script is fairly simple, it alows you to use a text file as the source for the message text rather than the event dialogs. My major reason for writing it is that I don't like using batch entry and it makes it easier to spell check/modify things; as opposed to wading through all of the individual events.
Screenshots
There really aren't any relevant screenshots that would show what this script does.
Script
[rgss]class Game_Map
#By Phoenixia
def build_heap
@text_heap = {}
temp = {}
page_temp = []
leaf_temp = []
label = ""
title = ""
start_seq = 0
File.open("Text.txt", "r") do |file|
file.each_line() do |line|
case start_seq
when 0
title = line.chomp
start_seq += 1
next
when 1
line.chomp!.slice!(0)
label = line
start_seq += 1
next
end
if line.include?(":EOF")
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
@text_heap.store(title.dup(), temp.dup())
leaf_temp.clear
page_temp.clear
temp.clear
next
elsif !line.include?("\t")
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
@text_heap.store(title.dup(), temp.dup())
page_temp.clear
leaf_temp.clear
temp.clear
label = ""
title = line.chomp
next
elsif line.include?("\t\t")
line.slice!(0..1)
leaf_temp << line.dup()
next
elsif line.include?("*****")
page_temp << leaf_temp.dup()
leaf_temp.clear
next
else
unless label.empty?
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
leaf_temp.clear
page_temp.clear
end
line.chomp!.slice!(0)
label = line.dup()
next
end
end
end
end
def get_stacks
if @text_heap and @text_heap.include?(@map_id.to_s)
@text_stacks.clear if @text_stacks
@text_stacks = @text_heap[@map_id.to_s].dup()
end
end
def get_stack(label)
get_stacks if !@text_stacks
@text_stack.clear if @text_stack
@text_stack = @text_stacks[label].dup.reverse!
end
def stack?
return !@text_stack.empty?
end
def stack_pop
leaf = @text_stack.pop
lines = leaf.size
text = ""
leaf.each() {|line| text += line}
return [lines,text]
end
end
[/rgss]
[rgss]$game_map.get_stacks
[/rgss]
[rgss]if $game_temp.message_text != nil
# End
return false
end
stack_flag = $game_map.stack?
# Set message end waiting flag and callback
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
# Set message text on first line
unless stack_flag
$game_temp.message_text = @list[@index].parameters[0] + "\n"
line_count = 1
else
leaf = $game_map.stack_pop
line_count = leaf[0]
$game_temp.message_text = leaf[1]
end
# Loop
loop do
# If next event command text is on the second line or after
if @list[@index+1].code == 401 and !stack_flag
# Add the second line or after to message_text
$game_temp.message_text += @list[@index+1].parameters[0] + "\n"
line_count += 1
# If event command is not on the second line or after
else
# If next event command is show choices
if @list[@index+1].code == 102
# If choices fit on screen
if @list[@index+1].parameters[0].size <= 4 - line_count
# Advance index
@index += 1
# Choices setup
$game_temp.choice_start = line_count
setup_choices(@list[@index].parameters)
end
# If next event command is input number
elsif @list[@index+1].code == 103
# If number input window fits on screen
if line_count < 4
# Advance index
@index += 1
# Number input setup
$game_temp.num_input_start = line_count
$game_temp.num_input_variable_id = @list[@index].parameters[0]
$game_temp.num_input_digits_max = @list[@index].parameters[1]
end
end
# Continue
return true
end
# Advance index
@index += 1
end
end
[/rgss]
Instructions
Paste the Game_Map portion of the script anywhere above main. The $game_map.get_stacks goes beneath
@message_window = Window_Message.new in Scene_Map inside of the main method. Overwrite comand101 in the interpreter with the rest of the code.
Using the text file: The file from which the messages are read is a text file inside of the flder containing your game; by default it's named Text.txt. The file uses labels to determine which map and which conversation are being called. Map id's are untabbed, conversation labels are tabbed, as are seperators, actual text is double tabbed. For example:
Has two different conversations "label a" and "label b". The stars divide up the blocks of text, each block is one message window's worth of content. So, on the map with id 1 the "label a" conversation is one window displaying
the a, b, c, d each on its own line, then the next window would display e, then f, g, h. If we wanted to add more, we would just add more labels. If we wanted to start on map 2, we would just start a new line and put 2 without any tabs; then everything beneath it would be the conversations for map 2.
On the last line, you need to put ":EOF", else it won't read everything.
When using it in the game: At the start of the event put "$game_map.get_stack("LABEL")", where LABEL is the
label you used for what this event will be saying. Then, everytime you cal a message window, just leave it blank, and it will show whatever message you have in the file instead; every blank window moves it on to the next message from the file.
Choices: If you have a choice that wil change the flow of the convesation inside of your event, then you will need to call $game_map.get_stack("LABEL") under each branch for whatever labels deal with that branch, same goes for anyother type of conditional branching.
FAQ
Nothing yet.
Compatibility
I write all of my own scripts, so I don't know about any compatibility issues, however if any come up, I'll be sure to add them here, let me know.
Author's Notes
Just a few things:
1.) There is nothing that prohibits players from modifying your text, however you could easily run the file through a simple cipher to prevent this. You could also Marshal it, though neither really matters if someone is determined, just pointing it out.
2.) If you wanted to increase the width or number of lines used in your message window, you might want to use this since text editors have no limitations on such things; whereas the message dialog does.
Terms and Conditions
I don't really care if you give me credit, though it would be nice. All I ask is that you leave my name in the comment at the top of the script. Also, if you are actually making a commercial game with XP, I could care less if you use this in it.
By: Phoenixia
Introduction
This script is fairly simple, it alows you to use a text file as the source for the message text rather than the event dialogs. My major reason for writing it is that I don't like using batch entry and it makes it easier to spell check/modify things; as opposed to wading through all of the individual events.
Screenshots
There really aren't any relevant screenshots that would show what this script does.
Script
[rgss]class Game_Map
#By Phoenixia
def build_heap
@text_heap = {}
temp = {}
page_temp = []
leaf_temp = []
label = ""
title = ""
start_seq = 0
File.open("Text.txt", "r") do |file|
file.each_line() do |line|
case start_seq
when 0
title = line.chomp
start_seq += 1
next
when 1
line.chomp!.slice!(0)
label = line
start_seq += 1
next
end
if line.include?(":EOF")
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
@text_heap.store(title.dup(), temp.dup())
leaf_temp.clear
page_temp.clear
temp.clear
next
elsif !line.include?("\t")
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
@text_heap.store(title.dup(), temp.dup())
page_temp.clear
leaf_temp.clear
temp.clear
label = ""
title = line.chomp
next
elsif line.include?("\t\t")
line.slice!(0..1)
leaf_temp << line.dup()
next
elsif line.include?("*****")
page_temp << leaf_temp.dup()
leaf_temp.clear
next
else
unless label.empty?
page_temp << leaf_temp.dup()
temp.store(label.dup(), page_temp.dup())
leaf_temp.clear
page_temp.clear
end
line.chomp!.slice!(0)
label = line.dup()
next
end
end
end
end
def get_stacks
if @text_heap and @text_heap.include?(@map_id.to_s)
@text_stacks.clear if @text_stacks
@text_stacks = @text_heap[@map_id.to_s].dup()
end
end
def get_stack(label)
get_stacks if !@text_stacks
@text_stack.clear if @text_stack
@text_stack = @text_stacks[label].dup.reverse!
end
def stack?
return !@text_stack.empty?
end
def stack_pop
leaf = @text_stack.pop
lines = leaf.size
text = ""
leaf.each() {|line| text += line}
return [lines,text]
end
end
[/rgss]
[rgss]$game_map.get_stacks
[/rgss]
[rgss]if $game_temp.message_text != nil
# End
return false
end
stack_flag = $game_map.stack?
# Set message end waiting flag and callback
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
# Set message text on first line
unless stack_flag
$game_temp.message_text = @list[@index].parameters[0] + "\n"
line_count = 1
else
leaf = $game_map.stack_pop
line_count = leaf[0]
$game_temp.message_text = leaf[1]
end
# Loop
loop do
# If next event command text is on the second line or after
if @list[@index+1].code == 401 and !stack_flag
# Add the second line or after to message_text
$game_temp.message_text += @list[@index+1].parameters[0] + "\n"
line_count += 1
# If event command is not on the second line or after
else
# If next event command is show choices
if @list[@index+1].code == 102
# If choices fit on screen
if @list[@index+1].parameters[0].size <= 4 - line_count
# Advance index
@index += 1
# Choices setup
$game_temp.choice_start = line_count
setup_choices(@list[@index].parameters)
end
# If next event command is input number
elsif @list[@index+1].code == 103
# If number input window fits on screen
if line_count < 4
# Advance index
@index += 1
# Number input setup
$game_temp.num_input_start = line_count
$game_temp.num_input_variable_id = @list[@index].parameters[0]
$game_temp.num_input_digits_max = @list[@index].parameters[1]
end
end
# Continue
return true
end
# Advance index
@index += 1
end
end
[/rgss]
Instructions
Paste the Game_Map portion of the script anywhere above main. The $game_map.get_stacks goes beneath
@message_window = Window_Message.new in Scene_Map inside of the main method. Overwrite comand101 in the interpreter with the rest of the code.
Using the text file: The file from which the messages are read is a text file inside of the flder containing your game; by default it's named Text.txt. The file uses labels to determine which map and which conversation are being called. Map id's are untabbed, conversation labels are tabbed, as are seperators, actual text is double tabbed. For example:
1
label a
a
b
c
d
*****
e
*****
f
g
h
label b
i
label a
a
b
c
d
*****
e
*****
f
g
h
label b
i
Has two different conversations "label a" and "label b". The stars divide up the blocks of text, each block is one message window's worth of content. So, on the map with id 1 the "label a" conversation is one window displaying
the a, b, c, d each on its own line, then the next window would display e, then f, g, h. If we wanted to add more, we would just add more labels. If we wanted to start on map 2, we would just start a new line and put 2 without any tabs; then everything beneath it would be the conversations for map 2.
On the last line, you need to put ":EOF", else it won't read everything.
When using it in the game: At the start of the event put "$game_map.get_stack("LABEL")", where LABEL is the
label you used for what this event will be saying. Then, everytime you cal a message window, just leave it blank, and it will show whatever message you have in the file instead; every blank window moves it on to the next message from the file.
Choices: If you have a choice that wil change the flow of the convesation inside of your event, then you will need to call $game_map.get_stack("LABEL") under each branch for whatever labels deal with that branch, same goes for anyother type of conditional branching.
FAQ
Nothing yet.
Compatibility
I write all of my own scripts, so I don't know about any compatibility issues, however if any come up, I'll be sure to add them here, let me know.
Author's Notes
Just a few things:
1.) There is nothing that prohibits players from modifying your text, however you could easily run the file through a simple cipher to prevent this. You could also Marshal it, though neither really matters if someone is determined, just pointing it out.
2.) If you wanted to increase the width or number of lines used in your message window, you might want to use this since text editors have no limitations on such things; whereas the message dialog does.
Terms and Conditions
I don't really care if you give me credit, though it would be nice. All I ask is that you leave my name in the comment at the top of the script. Also, if you are actually making a commercial game with XP, I could care less if you use this in it.