Jeff the Green
Member
Okay, I've been working on an alternative way to input text. I load it from a .txt, and call it using the Show Text command.
I'm using Trickster's load_data_from_txt to create a hash that looks like this:
{'conversation1' => ['Hi there.', 'Hello to you too.'],
'conversation2' => ['Goodbye.', 'Farewell.']}
And then I modified the Interpreter command101 so that it checks to see if the first line of text is one of the keys of the hash and the second line is a number or a range. If they're not, then it displays the message as normal, but otherwise it goes to my mod. My mod parses the first line of the message to get the correct array and the second line to get the right string from the array, and then displays that in the message box. All of that works fine if I use an integer (which returns a single string), but I can't figure out how to get it to work with the range. It keeps showing me the last string from the range (e.g. 1-2 of conversation2 would just give 'Farewell.' (one message) instead of 'Goodbye.' 'Farewell.' (two messages). Here's a link to my .zip (http://ivi.b1.jcink.com/index.php?act=Attach&type=post&id=410), but here's the code from Interpreter that I changed.
I'm using Trickster's load_data_from_txt to create a hash that looks like this:
{'conversation1' => ['Hi there.', 'Hello to you too.'],
'conversation2' => ['Goodbye.', 'Farewell.']}
And then I modified the Interpreter command101 so that it checks to see if the first line of text is one of the keys of the hash and the second line is a number or a range. If they're not, then it displays the message as normal, but otherwise it goes to my mod. My mod parses the first line of the message to get the correct array and the second line to get the right string from the array, and then displays that in the message box. All of that works fine if I use an integer (which returns a single string), but I can't figure out how to get it to work with the range. It keeps showing me the last string from the range (e.g. 1-2 of conversation2 would just give 'Farewell.' (one message) instead of 'Goodbye.' 'Farewell.' (two messages). Here's a link to my .zip (http://ivi.b1.jcink.com/index.php?act=Attach&type=post&id=410), but here's the code from Interpreter that I changed.
Code:
#==============================================================================
# ** Interpreter (part 3)
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Show Text
#--------------------------------------------------------------------------
def command_101
# If other text has been set to message_text
if $game_temp.message_text != nil
# End
return false
end
# Check for range
if @list[@index+1].code == 401
second_line = @list[@index+1].parameters[0].dup
if $data_dialog.has_key?(@list[@index].parameters[0])
is_integer = $data_dialog[@list[@index].parameters[0]][second_line.to_i] != nil
is_range = second_line.sub!('...', ' ')
if is_range or is_integer
# Go to special message processer
return command_101_part_2
end
end
end
# 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
$game_temp.message_text = @list[@index].parameters[0] + "\n"
line_count = 1
# Loop
loop do
# If next event command text is on the second line or after
if @list[@index+1].code == 401
# 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
#--------------------------------------------------------------------------
# * Show Text (From $data_dialog)
#--------------------------------------------------------------------------
def command_101_part_2
# Set message end waiting flag and callback
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false}
dialog = @list[@index].parameters[0]
line_string = @list[@index+1].parameters[0].dup
line_string.sub!('...', ' ')
line_array = line_string.split(' ')
if line_array.size == 1
lines = line_array[0].to_i
else
min = line_array[0].to_i - 1
max = line_array[1].to_i - 1
lines = min..max
end
if lines.is_a?(Integer)
@message_waiting = true
$game_temp.message_proc = Proc.new { @message_waiting = false }
$game_temp.message_text = $data_dialog[dialog][lines]
elsif lines.is_a?(Range)
for i in lines
$game_temp.message_text = $data_dialog[dialog][lines][i].dup
end
end
return true
end
end