RPG Maker Forums

Hey, everyone. I've just spent the last 5 hours trying to get like three different journal scripts to work in my game. None of them do.

I think I've got my heart set on Notebook by Jet, but I can't seem to get it to work. Its supposed to read and pull up text files from my game directory's Notebook file, but it doesn't. I don't get an error or anything,

the scene call simply does not work.

Here's the script (I don't know how to do the spoiler thing): 

#===============================================================================
# Notebook Menu
# By Jet10985 (Jet)
#===============================================================================
# This script will add a Notebook menu to the game, which can be used to add
# entries to the notebook that the player can read.
# This script has: 6 customization options.
#===============================================================================
# Overwritten Methods:
# None
#-------------------------------------------------------------------------------
# Aliased methods:
# Scene_Title: initialize
#===============================================================================
=begin
To use this script, you need to have a folder in your game directory called
Notebook

This is where your .txt files should be located.
This script runs solely on the .txt files in the folder, and it's where it
grabs the files for the .rvdata conversion if used.
--------------------------------------------------------------------------------
To add new entries to the journal, use this in an event "Script..." command

add_entry("filename")

"filename" should be the name of a .txt file in the Notebook folder, excluding
the .txt. So say i have a file called Test.txt: add_entry("Test")

Even if you use the .rvdata file, the filenames stay the same so make sure
you remember your filenames.
--------------------------------------------------------------------------------
You can call the journal scene with this code in an event "Script..." command:

$scene = Scene_Notebook.new

The journal scene will be inaccessable unless the player has at least 1 entry
--------------------------------------------------------------------------------
If the text entry is too long height-wise to be shown completely, then the
player needs to use Q to scroll up, or W to scroll down.
--------------------------------------------------------------------------------
To force a next line in the text, put \line inside the .txt file where you
want to force text to the next line
=end

module Notebook
  
  # Would you like to convert all .txt files in the "Notebook" folder to a
  # .rvdata data file which can be encrpyted with the game, and used with
  # the USE_RVDATA_FILE option?
  DO_CONVERSION_TO_RVDATA = false
  
  # Would you like to use the Notebook.rvdata file generated with the
  # DO_CONVERSION_TO_RVDATA instead of the .txt files in the "Notebook" folder?
  USE_RVDATA_FILE = false
  
  # What is the notebook called?
  NOTEBOOK_NAME = "Notebook"
  
  # What font does the notebook use? The first item is the primary font you
  # want, and it will go through each item if the font doesn't exist
  # until it finds a font that does exist.
  NOTEBOOK_FONT = ["Verdana", "Arial", "Courier New"]
  
  # What is the font size in the notebook? 20 is default
  NOTEBOOK_FONT_SIZE = 20
  
  # How much space will be given for each line? 24 is default
  NOTEBOOK_WLH = 24
  
end

#===============================================================================
# DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO.
#===============================================================================
class Game_System
  
  attr_accessor :notebook_entries
  
  alias jet1835_initialize initialize unless $@
  def initialize(*args, &block)
    @notebook_entries = []
    jet1835_initialize(*args, &block)
  end
end

class Game_Interpreter
  
  def add_entry(filename)
    unless $game_system.notebook_entries.include?(filename)
      $game_system.notebook_entries.push(filename)
    end
  end
end

class Scene_Title
  
  alias jet1934_initialize initialize unless $@
  def initialize(*args, &block)
    convert_txt if Notebook::DO_CONVERSION_TO_RVDATA && $TEST
    jet1934_initialize(*args, &block)
  end
  
  def convert_txt
    file = Dir.entries("Notebook")
    file.reverse!
    2.times {|i| file.pop }
    file.reverse!
    if file.empty?
      p "No files found in Notebook, aborting conversion process."
    end
    text_hash = {}
    for txt in file
      text_hash[txt] = File.open("Notebook/#{txt}", "r") {|a| a.read}
    end
    b = File.new("Data/Notebook.rvdata", "wb") 
    Marshal.dump(text_hash, B)
    b.close
    p "Notebook file successfully converted."
  end
end

class String
  
  def each_word
    array = self.split(" ")
    if block_given?
      array.each {|a| yield a }
    else
      return array
    end
  end
end

class Window_Notebook < Window_Base
  
  include Notebook
  
  def initialize(filename)
    super(160, 56, Graphics.width - 160, Graphics.height - 56)
    @filename = filename
    refresh(@filename)
  end
  
  def refresh(filename)
    self.oy = 0
    form_bitmap_rect(filename)
    self.contents.font.name = NOTEBOOK_FONT
    self.contents.font.size = NOTEBOOK_FONT_SIZE
    wlh = NOTEBOOK_WLH
    i = 0
    @file_text.each_line {|line|
      text = line.gsub(/\r|\n/i, "")
      self.contents.draw_text(0, 0 + i * wlh, self.width - 32, wlh, text)
      i += 1
    }
  end
  
  def form_bitmap_rect(filename)
    if USE_RVDATA_FILE
      file = load_data("Data/Notebook.rvdata")[filename + ".txt"]
    else
      file = File.open("Notebook/#{filename}.txt", "r") {|a| a.read }
    end
    new_text = ""
    width_taken = 0
    height_taken = 0
    file.gsub!(/\r\n/i, " ")
    file.gsub!(/\\line/i, " \\xjet ")
    file.each_word {|word|
      width_taken += self.contents.text_size("#{word} ").width
      if word == "\\xjet"
        width_taken = 0
        new_text.concat("\n")
        height_taken += NOTEBOOK_WLH
      elsif width_taken > self.width - 32
        width_taken = 0
        new_text.concat("\n#{word} ")
        width_taken += self.contents.text_size("#{word} ").width
        height_taken += NOTEBOOK_WLH
      else
        new_text.concat("#{word} ")
      end
    }
    @file_text = new_text
    @height_taken = height_taken
    self.contents = Bitmap.new(self.width - 32, @height_taken + 32)
  end
end

class Window_Entries < Window_Base

  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end

  def refresh
    contents.clear
    contents.font.color = system_color
    contents.draw_text(0, 0, 100, 24, "Entries:")
    contents.font.color = normal_color
    contents.draw_text(104, 0, 40, 24, $game_system.notebook_entries.size, 1) 
  end
end


class Scene_Notebook < Scene_Base
  
  def initialize
    @return_scene = $scene.class.to_s
    @return = false
  end
  
  def start
    if $game_system.notebook_entries.empty?
      $scene = eval(@return_scene + ".new")
      @return = true
      return
    end
    super
    create_menu_background
    @help_window = Window_Help.new
    @help_window.set_text(Notebook::NOTEBOOK_NAME, 1)
    @notebook_window = Window_Notebook.new($game_system.notebook_entries[0])
    @entries_window = Window_Entries.new(0, Graphics.height - 54)
    @command_window = Window_Command.new(160, $game_system.notebook_entries)
    @command_window.height = Graphics.height - 110
    @command_window.y += 56
  end
  
  def update
    return if @return
    super
    update_menu_background
    old_index = @command_window.index
    @command_window.update
    if old_index != @command_window.index
      @notebook_window.refresh(@command_window.commands[@command_window.index])
    end
    @notebook_window.update
    if Input.trigger?(Input:: B)
      return_scene
    end
    if @notebook_window.contents.height > @notebook_window.height - 32
      wlh = Notebook::NOTEBOOK_WLH
      if Input.trigger?(Input::RIGHT)
        @notebook_window.oy = [@notebook_window.oy + wlh, 
          @notebook_window.contents.height - @notebook_window.height + 32].min
      elsif Input.trigger?(Input::LEFT)
        @notebook_window.oy = [@notebook_window.oy - wlh, 
          0].max
      end
    end
  end
  
  def return_scene
    $scene = eval(@return_scene + ".new")
  end
  
  def perform_transition
    super unless @return
  end
  
  def terminate
    return if @return
    super
    dispose_menu_background
    @help_window.dispose
    @notebook_window.dispose
    @entries_window.dispose
    @command_window.dispose
  end
end

I would look at the demo if I could, but the forum it's posted on won't send me the confirmation e-mail for me to register, thus I can't. I'm not looking for a quest journal or anything, just a diary where my protagonist can voice his thoughts on what's happening. Here's the link to the forum post: http://www.rpgmakervx.net/index.php?showtopic=49867.

 

Any help would be appreciated! I'm kind of a little desperate.

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,048
Messages
1,018,545
Members
137,834
Latest member
EverNoir
Top