[RGSS3] Script re-formatting

ZirconStorms

Veteran
Veteran
Joined
Dec 22, 2014
Messages
359
Reaction score
111
First Language
English
Primarily Uses
RMVXA
If possible, I'd like to know how to fix some VX Ace script that's now broken due to some forum error.
Link: https://forums.rpgmakerweb.com/index.php?threads/rstw-reedos-scrolling-text-window.18424/
(Check the spoiler for "Script")

I managed to get a few pieces of it fixed, but it's far from usable with what I've done. I've pasted what I've done below + attached it as a txt file.

Code:
################################################################################
#RSTW - Reedo's Scrolling Text Window
## Version 1.0
## September 24, 2013
## By Reedo
##############################################################################
# REFERENCES#
### None. This is an original script by Reedo.#
###############################################################################
# FEATURES#### + New scene with single-window scrolling text area.
## + Menu option for displaying scene, or various script calls.
## + Scene loads plain text file automatically when shown.
## + Text file supports game message slash-command mark-up.
## + Text is scrolled using up/down arrows, sped up with "Z" key (A button),
## and can jump to top or bottom with page up (L) and page down (R).
## + Text can be loaded in "Block mode" to only read up to a specified
## number of text blocks (paragraphs, seperated by a blank line).
## + Block mode index (max blocks shown) can be controlled automatically
## via an associated game variable value, or by script using a static
## property on the scene itself.
## + Scene can always be shown "own demand" via script calls with the
## supplied message text, even if a text file was loaded.
## + Text files can be up to 15K or so with reasonable performance.
## (the upper limit of text size is not fully tested)
## + The Window_Reedo_ScrollText class can be reused by other scenes.
## + The Scene_Reedo_ScrollText class can be used as a basis for other scenes.
################################################################################

#
## COMPATIBILITY##
## Should be compatible with most other scripts.
###############################################################################
## REQUIREMENTS#### None.## Optional text file containing text to display.
###############################################################################
## INSTALLATION##
## Plug-and-play##
## Insert below Materials, above other add-on scripts.##
#############################################################################
## RIGHTS & RESTRICTIONS##
## As with most Reedo scripts, this script is free to re-use, as-is,
## in personal, educational, and commercial RPGVX Ace development projects,
## providing that: this script is credited in writing displayed readily
## to the user of the final compiled code assembly.##
## Reedo retains all rights of intellect and ownership.
## You forego all rights of warranty by utilizing this script.##
#############################################################################
## Values from this class are used for settings in the module below.
## Do not modify this class directly.
class RSTW_LoadMode
  NONE = 0 # Specifies that the loading process do nothing.
  ALL = 1 # Reads the entire text file into the window. BLOCK = 2
  # Reads the text file in blocks (up to a blank line) for the
  # maximum number of blocks defined by the block index. CUSTOM = 3
  # Allows for custom loading by overriding read_custom.
end
###############################################################################
## USER OPTIONS##
#############################################################################
module RSTW # Display a command in the menu for opening the scene.
  USE_MENU_COMMAND = false # The name of the command when displayed.
  MENU_COMMAND_NAME = "Journal"
  # True to load the specified text file whenever the scene opens.
  LOAD_ON_START = true # The processing mode used to load the text file.
  LOAD_MODE = nil
  # The Id of the game variable used to store the index of the last displayed
  #text block when using block-mode processing, or nil to use the scene's
  # static block_index property.
  BLOCK_INDEX_VARIABLE = nil
  # The name of the text file to load when LOAD_ON_START is true.
  TEXT_FILE = "Data/Journal.txt"
  # The message displayed in the window when the text file fails to load.
  FILE_READ_ERROR = "[ERROR READING FILE]"
  # The fastest scroll speed for the window; normal scroll is half this value.
  WINDOW_SCROLL_SPEED = 8
end
###############################################################################
## MAIN SCRIPT##
#############################################################################
## EDITS BEYOND THIS POINT ARE AT YOUR OWN RISK!!!##
############################################################################
## Base class override to add menu command
class Window_MenuCommand
  alias rstw_wmc_add_original_commands add_original_commands
  def add_original_commands
    rstw_wmc_add_original_commands
    add_command(RSTW::MENU_COMMAND_NAME, :RSTWCommand, main_commands_enabled) if

RSTW::USE_MENU_COMMAND
  end
  end
    # This is the core scrolling text window which can be reused in other

scenes.
    class Window_Reedo_ScrollText < Window_Base
      attr_accessor :text
      attr_accessor :text_scroll_speed
      attr_accessor :terminate_at_end
      def initialize
        super(0, 0, Graphics.width, Graphics.height)
        self.arrows_visible = true
        @handler = {}
        @text = ""
        @text_scroll_speed = RSTW::WINDOW_SCROLL_SPEED
        @terminate_at_end = false
        @scroll_pos = 0
        @scroll_on = false
        @scroll_dir = 1
        hide
      end
      def update
        super
        update_message if @text
        process_handling
      end
      def process_handling
        @scroll_on = false
        return unless open? && active
        return process_ok if ok_enabled? && Input.trigger?(:C)
        return process_cancel
        if cancel_enabled? && Input.trigger?(:L) && (@scroll_pos > 0) #if

cancel_enabled? && Input.trigger?:) scrollDelta = contents.height - height +

standard_padding * 2 if Input.trigger?:)L) && (@scroll_pos > 0)
        then @scroll_pos = 0
        end
        if Input.trigger?(:R) && (@scroll_pos < scrollDelta)
          then @scroll_pos = scrollDelta
        end
        if Input.press?(:UP) && (@scroll_pos > 0) then @scroll_on = true
          @scroll_dir = -1
          return
        end
        if Input.press?(:DOWN) && (@scroll_pos < scrollDelta)
          then @scroll_on = true
          @scroll_dir = 1
          return
        end
      end
      def ok_enabled?
        handle?(:ok)
      end
      def cancel_enabled?
        handle?(:cancel)
      end
      def process_ok
        if current_item_enabled?
          Sound.play_ok
          Input.update
          deactivate
          call_ok_handler
        else
          Sound.play_buzzer
        end
      end
      def call_ok_handler
        call_handler(:ok)
      end
      def process_cancel
        Sound.play_cancel
        Input.update
        deactivate
        call_cancel_handler
      end
      def
        call_cancel_handler
        call_handler(:cancel)
      end
      def set_handler(symbol, method)
        @handler[symbol] = method
      end
      def handle?(symbol)
        @handler.include?(symbol)
      end
      def call_handler(symbol)
        @handler[symbol].call if handle?(symbol)
      end
      def start_message(messageText = nil)
        @text = messageText if messageText
        refresh
        show
      end
      def refresh
        reset_font_settings
        update_all_text_height
        create_contents
        draw_text_ex(4, 0, @text)
      end
      def update_all_text_height
        @all_text_height = 1
        convert_escape_characters(@text).each_line do |line| @all_text_height +=

calc_line_height(line, false)
      end
      reset_font_settings
    end
    def contents_height
      @all_text_height ? @all_text_height : super
    end
    def update_message
      @scroll_pos += (scroll_speed * @scroll_dir) if @scroll_on
      self.oy = @scroll_pos
      terminate_message if ((@scroll_pos >= contents.height) &&

@terminate_at_end)
    end
    def scroll_speed
      @text_scroll_speed * (show_fast? ? 1.0 : 0.5)
    end
    def show_fast?
      (Input.press?(:A) || Input.press?(:C))
    end
    def terminate_message
      @text = nil
      hide
    end
  end
  # Base class override to provide menu option handler
  class Scene_Menu
    alias rstw_sm_create_command_window create_command_window
    def create_command_window
      rstw_sm_create_command_window
      @command_window.set_handler(:RSTWCommand, method(:command_reedo_show_stw))
    end
    def command_reedo_show_stw
      SceneManager.call(Scene_Reedo_ScrollText)
    end
  end
  # The custom scene class. This class can be extended to make other scenes that
  # use the scrolling text window. Additional windows can be added as needed.
  class Scene_Reedo_ScrollText < Scene_Base
    @@selfshow = false
    @@selftext = ""
    @@block_index = 0
    def self.display(text)
      @@selfshow = true
      @@selftext = text
      SceneManager.call(Scene_Reedo_ScrollText)
    end
    def self.block_index
      @@block_index
    end
    def self.block_index=(value)
      @@block_index = value
    end
    def start
      super
#~       create_background
      create_text_window if @@selfshow
      @@selfshow = false
      show_text(@@selftext)
    else
      show_text(load_scene_text) if RSTW::LOAD_ON_START
    end
  end
  def load_scene_text
    case RSTW::LOAD_MODE
    when RSTW_LoadMode::NONE
      when RSTW_LoadMode::CUSTOM
        read_custom
        when RSTW_LoadMode::ALL
          read_all_text
          when RSTW_LoadMode::BLOCK
            read_block_text
          end
        end
        # override to provide custom text loading when scene begins
        # method should return a string containing the text to display
        # should provide acceptable performance up to 10,000 characters
        def read_custom
        end
        def
          read_all_text
          result = ""
          begin
            File.open(RSTW::TEXT_FILE) do |file|
              result = file.read
          end
        rescue
          result = RSTW::FILE_READ_ERROR
        end
        return
        result
      end
      def read_block_text
        result = ""
        max = $game_variables[RSTW::BLOCK_INDEX_VARIABLE]
        if RSTW::BLOCK_INDEX_VARIABLE
          max = @@block_index
          if !max index = 0
            begin
              File.open(RSTW::TEXT_FILE)
#~               do |file| file.each_line do |line|
#~                 break if index > max result += line
#~               if line == "\n"
#~               end
            end
#~           rescue
            result = RSTW::FILE_READ_ERROR
          end
          return
          result
        end
        def terminate
          super
          dispose_background
        end
#~         def create_background
#~           @background_sprite = Sprite.new
#~           @background_sprite.bitmap = SceneManager.background_bitmap
#~           @background_sprite.color.set(16, 16, 16, 128)
#~         end
        def dispose_background
          @background_sprite.dispose
        end
        def create_text_window
          @text_window = Window_Reedo_ScrollText.new
          @text_window.set_handler(:cancel, method(:return_scene))
        end
        def show_text(text)
          @text_window.start_message(text)
          @text_window.activate end
        def close_text
          @text_window.terminate_message
        end
      end
#~     end
#~     end
 

Attachments

MobiusXVI

Game Maker
Veteran
Joined
Mar 20, 2013
Messages
383
Reaction score
91
First Language
English
Primarily Uses
I've cleaned it up enough that it doesn't produce errors anymore, but it still doesn't seem to work as expected.
Code:
################################################################################
#RSTW - Reedo's Scrolling Text Window
## Version 1.0
## September 24, 2013
## By Reedo
##############################################################################
# REFERENCES#
### None. This is an original script by Reedo.#
###############################################################################
# FEATURES#### + New scene with single-window scrolling text area.
## + Menu option for displaying scene, or various script calls.
## + Scene loads plain text file automatically when shown.
## + Text file supports game message slash-command mark-up.
## + Text is scrolled using up/down arrows, sped up with "Z" key (A button),
## and can jump to top or bottom with page up (L) and page down (R).
## + Text can be loaded in "Block mode" to only read up to a specified
## number of text blocks (paragraphs, seperated by a blank line).
## + Block mode index (max blocks shown) can be controlled automatically
## via an associated game variable value, or by script using a static
## property on the scene itself.
## + Scene can always be shown "own demand" via script calls with the
## supplied message text, even if a text file was loaded.
## + Text files can be up to 15K or so with reasonable performance.
## (the upper limit of text size is not fully tested)
## + The Window_Reedo_ScrollText class can be reused by other scenes.
## + The Scene_Reedo_ScrollText class can be used as a basis for other scenes.
#################################################################################
## COMPATIBILITY##
## Should be compatible with most other scripts.
###############################################################################
## REQUIREMENTS#### None.## Optional text file containing text to display.
###############################################################################
## INSTALLATION##
## Plug-and-play##
## Insert below Materials, above other add-on scripts.##
#############################################################################
## RIGHTS & RESTRICTIONS##
## As with most Reedo scripts, this script is free to re-use, as-is,
## in personal, educational, and commercial RPGVX Ace development projects,
## providing that: this script is credited in writing displayed readily
## to the user of the final compiled code assembly.##
## Reedo retains all rights of intellect and ownership.
## You forego all rights of warranty by utilizing this script.##
#############################################################################
## Values from this class are used for settings in the module below.
## Do not modify this class directly.
class RSTW_LoadMode
  NONE = 0 # Specifies that the loading process do nothing.
  ALL = 1 # Reads the entire text file into the window.
  BLOCK = 2 # Reads the text file in blocks (up to a blank line) for the
  # maximum number of blocks defined by the block index.
  CUSTOM = 3 # Allows for custom loading by overriding read_custom.
end
###############################################################################
## USER OPTIONS##
#############################################################################
module RSTW # Display a command in the menu for opening the scene.
  USE_MENU_COMMAND = true # The name of the command when displayed.
  MENU_COMMAND_NAME = "Journal"
  # True to load the specified text file whenever the scene opens.
  LOAD_ON_START = true # The processing mode used to load the text file.
  LOAD_MODE = nil
  # The Id of the game variable used to store the index of the last displayed
  # text block when using block-mode processing, or nil to use the scene's
  # static block_index property.
  BLOCK_INDEX_VARIABLE = nil
  # The name of the text file to load when LOAD_ON_START is true.
  TEXT_FILE = "Data/Journal.txt"
  # The message displayed in the window when the text file fails to load.
  FILE_READ_ERROR = "[ERROR READING FILE]"
  # The fastest scroll speed for the window; normal scroll is half this value.
  WINDOW_SCROLL_SPEED = 8
end
###############################################################################
## MAIN SCRIPT##
#############################################################################
## EDITS BEYOND THIS POINT ARE AT YOUR OWN RISK!!!##
############################################################################
## Base class override to add menu command
class Window_MenuCommand
  alias rstw_wmc_add_original_commands add_original_commands

  def add_original_commands
    rstw_wmc_add_original_commands
    add_command(RSTW::MENU_COMMAND_NAME, :RSTWCommand, main_commands_enabled) if RSTW::USE_MENU_COMMAND
  end
end
# This is the core scrolling text window which can be reused in other scenes.
class Window_Reedo_ScrollText < Window_Base
  attr_accessor :text
  attr_accessor :text_scroll_speed
  attr_accessor :terminate_at_end

  def initialize
    super(0, 0, Graphics.width, Graphics.height)
    self.arrows_visible = true
    @handler = {}
    @text = ""
    @text_scroll_speed = RSTW::WINDOW_SCROLL_SPEED
    @terminate_at_end = false
    @scroll_pos = 0
    @scroll_on = false
    @scroll_dir = 1
    hide
  end

  def update
    super
    update_message if @text
    process_handling
  end

  def process_handling
    @scroll_on = false
    return unless open? && active
    return process_ok if ok_enabled? && Input.trigger?(:C)
    return process_cancel
    if cancel_enabled? && Input.trigger?(:L) && (@scroll_pos > 0) #if cancel_enabled? && Input.trigger?:) scrollDelta = contents.height - height + standard_padding * 2 if Input.trigger?:)L) && (@scroll_pos > 0)
    then
      @scroll_pos = 0
    end
    if Input.trigger?(:R) && (@scroll_pos < scrollDelta)
    then
      @scroll_pos = scrollDelta
    end
    if Input.press?(:UP) && (@scroll_pos > 0) then
      @scroll_on = true
      @scroll_dir = -1
      return
    end
    if Input.press?(:DOWN) && (@scroll_pos < scrollDelta)
    then
      @scroll_on = true
      @scroll_dir = 1
      return
    end
  end

  def ok_enabled?
    handle?(:ok)
  end

  def cancel_enabled?
    handle?(:cancel)
  end

  def process_ok
    if current_item_enabled?
      Sound.play_ok
      Input.update
      deactivate
      call_ok_handler
    else
      Sound.play_buzzer
    end
  end

  def call_ok_handler
    call_handler(:ok)
  end

  def process_cancel
    Sound.play_cancel
    Input.update
    deactivate
    call_cancel_handler
  end

  def call_cancel_handler
    call_handler(:cancel)
  end

  def set_handler(symbol, method)
    @handler[symbol] = method
  end

  def handle?(symbol)
    @handler.include?(symbol)
  end

  def call_handler(symbol)
    @handler[symbol].call if handle?(symbol)
  end

  def start_message(messageText = nil)
    @text = messageText if messageText
    refresh
    show
  end

  def refresh
    reset_font_settings
    update_all_text_height
    create_contents
    draw_text_ex(4, 0, @text)
  end

  def update_all_text_height
    @all_text_height = 1
    convert_escape_characters(@text).each_line do |line|
      @all_text_height += calc_line_height(line, false)
    end
    reset_font_settings
  end

  def contents_height
    @all_text_height ? @all_text_height : super
  end

  def update_message
    @scroll_pos += (scroll_speed * @scroll_dir) if @scroll_on
    self.oy = @scroll_pos
    terminate_message if ((@scroll_pos >= contents.height) && @terminate_at_end)
  end

  def scroll_speed
    @text_scroll_speed * (show_fast? ? 1.0 : 0.5)
  end

  def show_fast?
    (Input.press?(:A) || Input.press?(:C))
  end

  def terminate_message
    @text = nil
    hide
  end
end
# Base class override to provide menu option handler
class Scene_Menu
  alias rstw_sm_create_command_window create_command_window

  def create_command_window
    rstw_sm_create_command_window
    @command_window.set_handler(:RSTWCommand, method(:command_reedo_show_stw))
  end

  def command_reedo_show_stw
    SceneManager.call(Scene_Reedo_ScrollText)
  end
end
# The custom scene class. This class can be extended to make other scenes that
# use the scrolling text window. Additional windows can be added as needed.
class Scene_Reedo_ScrollText < Scene_Base
  @@selfshow = false
  @@selftext = ""
  @@block_index = 0

  def self.display(text)
    @@selfshow = true
    @@selftext = text
    SceneManager.call(Scene_Reedo_ScrollText)
  end

  def self.block_index
    @@block_index
  end

  def self.block_index=(value)
    @@block_index = value
  end

  def start
    super
    create_background
    create_text_window
    if @@selfshow
      @@selfshow = false
      show_text(@@selftext)
    else
      show_text(load_scene_text) if RSTW::LOAD_ON_START
    end
  end


  def load_scene_text
    case RSTW::LOAD_MODE
    when RSTW_LoadMode::NONE
    when RSTW_LoadMode::CUSTOM
      read_custom
    when RSTW_LoadMode::ALL
      read_all_text
    when RSTW_LoadMode::BLOCK
      read_block_text
    end
  end

# override to provide custom text loading when scene begins
# method should return a string containing the text to display
# should provide acceptable performance up to 10,000 characters
  def read_custom
  end

  def read_all_text
    result = ""
    begin
      File.open(RSTW::TEXT_FILE) do |file|
        result = file.read
      end
    rescue
      result = RSTW::FILE_READ_ERROR
    end
    return result
  end

  def read_block_text
    result = ""
    max = $game_variables[RSTW::BLOCK_INDEX_VARIABLE]
    if RSTW::BLOCK_INDEX_VARIABLE
      max = @@block_index
      if !max index = 0
        begin
          File.open(RSTW::TEXT_FILE) do |file|
            file.each_line do |line|
              break if index > max
              result += line if line == "\n"
            end
          end
        rescue
          result = RSTW::FILE_READ_ERROR
        end
        return result
      end
    end
  end

  def terminate
    super
    dispose_background
  end

  def create_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = SceneManager.background_bitmap
    @background_sprite.color.set(16, 16, 16, 128)
  end

  def dispose_background
    @background_sprite.dispose
  end

  def create_text_window
    @text_window = Window_Reedo_ScrollText.new
    @text_window.set_handler(:cancel, method(:return_scene))
  end

  def show_text(text)
    @text_window.start_message(text)
    @text_window.activate
  end

  def close_text
    @text_window.terminate_message
  end
end
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,660
Reaction score
563
First Language
English
Primarily Uses
RMVXA
This is working for me now.

Code:
################################################################################
#RSTW - Reedo's Scrolling Text Window
## Version 1.0
## September 24, 2013
## By Reedo
##############################################################################
# REFERENCES#
### None. This is an original script by Reedo.#
###############################################################################
# FEATURES#### + New scene with single-window scrolling text area.
## + Menu option for displaying scene, or various script calls.
## + Scene loads plain text file automatically when shown.
## + Text file supports game message slash-command mark-up.
## + Text is scrolled using up/down arrows, sped up with "Z" key (A button),
## and can jump to top or bottom with page up (L) and page down (R).
## + Text can be loaded in "Block mode" to only read up to a specified
## number of text blocks (paragraphs, seperated by a blank line).
## + Block mode index (max blocks shown) can be controlled automatically
## via an associated game variable value, or by script using a static
## property on the scene itself.
## + Scene can always be shown "own demand" via script calls with the
## supplied message text, even if a text file was loaded.
## + Text files can be up to 15K or so with reasonable performance.
## (the upper limit of text size is not fully tested)
## + The Window_Reedo_ScrollText class can be reused by other scenes.
## + The Scene_Reedo_ScrollText class can be used as a basis for other scenes.
#################################################################################
## COMPATIBILITY##
## Should be compatible with most other scripts.
###############################################################################
## REQUIREMENTS#### None.## Optional text file containing text to display.
###############################################################################
## INSTALLATION##
## Plug-and-play##
## Insert below Materials, above other add-on scripts.##
#############################################################################
## RIGHTS & RESTRICTIONS##
## As with most Reedo scripts, this script is free to re-use, as-is,
## in personal, educational, and commercial RPGVX Ace development projects,
## providing that: this script is credited in writing displayed readily
## to the user of the final compiled code assembly.##
## Reedo retains all rights of intellect and ownership.
## You forego all rights of warranty by utilizing this script.##
#############################################################################
## Values from this class are used for settings in the module below.
## Do not modify this class directly.
class RSTW_LoadMode
  NONE = 0 # Specifies that the loading process do nothing.
  ALL = 1 # Reads the entire text file into the window.
  BLOCK = 2 # Reads the text file in blocks (up to a blank line) for the
  # maximum number of blocks defined by the block index.
  CUSTOM = 3 # Allows for custom loading by overriding read_custom.
end
###############################################################################
## USER OPTIONS##
#############################################################################
module RSTW # Display a command in the menu for opening the scene.
  USE_MENU_COMMAND = true # The name of the command when displayed.
  MENU_COMMAND_NAME = "Journal"
  # True to load the specified text file whenever the scene opens.
  LOAD_ON_START = true # The processing mode used to load the text file.
  LOAD_MODE = 1 # 0, 1, 2, 3 - RSTW_LoadMode
  # The Id of the game variable used to store the index of the last displayed
  # text block when using block-mode processing, or nil to use the scene's
  # static block_index property.
  BLOCK_INDEX_VARIABLE = nil
  # The name of the text file to load when LOAD_ON_START is true.
  TEXT_FILE = "Data/Journal.txt"
  # The message displayed in the window when the text file fails to load.
  FILE_READ_ERROR = "[ERROR READING FILE]"
  # The fastest scroll speed for the window; normal scroll is half this value.
  WINDOW_SCROLL_SPEED = 8
end
###############################################################################
## MAIN SCRIPT##
#############################################################################
## EDITS BEYOND THIS POINT ARE AT YOUR OWN RISK!!!##
############################################################################
## Base class override to add menu command
class Window_MenuCommand
  alias rstw_wmc_add_original_commands add_original_commands

  def add_original_commands
    rstw_wmc_add_original_commands
    add_command(RSTW::MENU_COMMAND_NAME, :RSTWCommand, main_commands_enabled) if RSTW::USE_MENU_COMMAND
  end
end
# This is the core scrolling text window which can be reused in other scenes.
class Window_Reedo_ScrollText < Window_Base
  attr_accessor :text
  attr_accessor :text_scroll_speed
  attr_accessor :terminate_at_end

  def initialize
    super(0, 0, Graphics.width, Graphics.height)
    self.arrows_visible = true
    @handler = {}
    @text = ""
    @text_scroll_speed = RSTW::WINDOW_SCROLL_SPEED
    @terminate_at_end = false
    @scroll_pos = 0
    @scroll_on = false
    @scroll_dir = 1
    hide
  end

  def update
    super
    update_message if @text
    process_handling
  end

  def process_handling
    @scroll_on = false
    return unless open? && active
    return process_ok if ok_enabled? && Input.trigger?(:C)
    return process_cancel if cancel_enabled? && Input.trigger?(:B)
    scrollDelta = contents.height - height + standard_padding * 2
    if Input.trigger?(:L) && (@scroll_pos > 0)
    then
      @scroll_pos = 0
    end
    if Input.trigger?(:R) && (@scroll_pos < scrollDelta)
    then
      @scroll_pos = scrollDelta
    end
    if Input.press?(:UP) && (@scroll_pos > 0) then
      @scroll_on = true
      @scroll_dir = -1
      return
    end
    if Input.press?(:DOWN) && (@scroll_pos < scrollDelta)
    then
      @scroll_on = true
      @scroll_dir = 1
      return
    end
  end

  def ok_enabled?
    handle?(:ok)
  end

  def cancel_enabled?
    handle?(:cancel)
  end

  def process_ok
    if current_item_enabled?
      Sound.play_ok
      Input.update
      deactivate
      call_ok_handler
    else
      Sound.play_buzzer
    end
  end

  def call_ok_handler
    call_handler(:ok)
  end

  def process_cancel
    Sound.play_cancel
    Input.update
    deactivate
    call_cancel_handler
  end

  def call_cancel_handler
    call_handler(:cancel)
  end

  def set_handler(symbol, method)
    @handler[symbol] = method
  end

  def handle?(symbol)
    @handler.include?(symbol)
  end

  def call_handler(symbol)
    @handler[symbol].call if handle?(symbol)
  end

  def start_message(messageText = nil)
    @text = messageText if messageText
    refresh
    show
  end

  def refresh
    reset_font_settings
    update_all_text_height
    create_contents
    draw_text_ex(4, 0, @text)
  end

  def update_all_text_height
    @all_text_height = 1
    convert_escape_characters(@text).each_line do |line|
      @all_text_height += calc_line_height(line, false)
    end
    reset_font_settings
  end

  def contents_height
    @all_text_height ? @all_text_height : super
  end

  def update_message
    @scroll_pos += (scroll_speed * @scroll_dir) if @scroll_on
    self.oy = @scroll_pos
    terminate_message if ((@scroll_pos >= contents.height) && @terminate_at_end)
  end

  def scroll_speed
    @text_scroll_speed * (show_fast? ? 1.0 : 0.5)
  end

  def show_fast?
    (Input.press?(:A) || Input.press?(:C))
  end

  def terminate_message
    @text = nil
    hide
  end
end
# Base class override to provide menu option handler
class Scene_Menu
  alias rstw_sm_create_command_window create_command_window

  def create_command_window
    rstw_sm_create_command_window
    @command_window.set_handler(:RSTWCommand, method(:command_reedo_show_stw))
  end

  def command_reedo_show_stw
    SceneManager.call(Scene_Reedo_ScrollText)
  end
end
# The custom scene class. This class can be extended to make other scenes that
# use the scrolling text window. Additional windows can be added as needed.
class Scene_Reedo_ScrollText < Scene_Base
  @@selfshow = false
  @@selftext = ""
  @@block_index = 0

  def self.display(text)
    @@selfshow = true
    @@selftext = text
    SceneManager.call(Scene_Reedo_ScrollText)
  end

  def self.block_index
    @@block_index
  end

  def self.block_index=(value)
    @@block_index = value
  end

  def start
    super
    create_background
    create_text_window
    if @@selfshow
      @@selfshow = false
      show_text(@@selftext)
    else
      show_text(load_scene_text) if RSTW::LOAD_ON_START
    end
  end


  def load_scene_text
    case RSTW::LOAD_MODE
    when RSTW_LoadMode::NONE
    when RSTW_LoadMode::CUSTOM
      read_custom
    when RSTW_LoadMode::ALL
      read_all_text
    when RSTW_LoadMode::BLOCK
      read_block_text
    end
  end

# override to provide custom text loading when scene begins
# method should return a string containing the text to display
# should provide acceptable performance up to 10,000 characters
  def read_custom
  end

  def read_all_text
    result = ""
    begin
      File.open(RSTW::TEXT_FILE) do |file|
        result = file.read
      end
    rescue
      result = RSTW::FILE_READ_ERROR
    end
    return result
  end
 
  def read_block_text
    result = ""
    max = $game_variables[RSTW::BLOCK_INDEX_VARIABLE] if RSTW::BLOCK_INDEX_VARIABLE
    max = @@block_index if !max
    index = 0
    begin
      File.open(RSTW::TEXT_FILE) do |file|
      file.each_line do |line|
        break if index > max
        result += line #+ "\n"
        index +=1 if line == "\n"
      end
    end
    rescue result = RSTW::FILE_READ_ERROR
    end
    return result
  end

  def terminate
    super
    dispose_background
  end

  def create_background
    @background_sprite = Sprite.new
    @background_sprite.bitmap = SceneManager.background_bitmap
    @background_sprite.color.set(16, 16, 16, 128)
  end

  def dispose_background
    @background_sprite.dispose
  end

  def create_text_window
    @text_window = Window_Reedo_ScrollText.new
    @text_window.set_handler(:cancel, method(:return_scene))
  end

  def show_text(text)
    @text_window.start_message(text)
    @text_window.activate
  end

  def close_text
    @text_window.terminate_message
  end
end
 
Last edited:

ZirconStorms

Veteran
Veteran
Joined
Dec 22, 2014
Messages
359
Reaction score
111
First Language
English
Primarily Uses
RMVXA
Gave it a shot, and Reedo's script works great. Thanks for your help, had a lot of trouble with this. Hopefully people can come accross this new fixed version of the script if they need it, since I'm not sure if commenting on the original thread is allowed anymore. If I can manage to figure out a solution for the Block option, I'll paste it somewhere in either thread in the future. / @MobiusXVI @Roninator2
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,299
Reaction score
11,712
First Language
English
Primarily Uses
RMVXA
@Roninator2 Is that more or less okay now? If it is, I can edit the original thread and substitute this version for the broken one.
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
2,660
Reaction score
563
First Language
English
Primarily Uses
RMVXA
@Kes If someone can complete the fix for the other options then that will be the complete version. For now you can at least use the script.
Up to you if you want to put this in place of the original script, but I feel making a link to this would be enough.
I may not continue to work on it as parts of it were a bit of guessing on my part since I have not learned ruby coding officially.

@Kes I edited my previous post. I got the Block function to work.

With this text file
Code:
      \{\{\C[12] Progress Journal\}\C[0]
\n
         \C[14]The Journey Begins\C[0]\}
\n
You begin your journey through the world, only to
find that there is much you still need to learn.
The first thing you have to do is find all of
the trainers in the town so that you can learn
how to be a grand adventurer.

         \{\C[14]Testing Your Skills\}
\n
\C[0]Having learned all about a great many things from
each of the trainers with whom you visited, you
are now tasked with venturing out into the wild
to find the entrance to the gloomy cave and
retrieve a Gloomshroom which can only be found in
the cave's deepest depths.

         \{\C[14]Stew and Brew\}
\n
\C[0]You proved that you can use your adventuring
skills by retrieving a Gloomshroom from deep within
the gloomy cave. Now it is time to learn again!
You are going to use that mushroom to learn to
make food and drink items.

         \{\C[14]Follow the Fat Cat\}
\n
\C[0]Now that you know how to make tasty food and
beverage, you can use that knowledge to make
snacks that animals will like. Use your new found
knowledge to capture a cat as a pet.
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,862
Messages
1,017,045
Members
137,569
Latest member
Shtelsky
Top