Has you read the instruction
Instruction
=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 (left) to scroll up, or (right) 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
Note book name change
NOTEBOOK_NAME = "Notebook"
For example, Notebook name
NOTEBOOK_NAME = "Hello Man"
Note book font change
NOTEBOOK_FONT = ["Verdana", "Arial", "Courier New"]
For example,
["Verdana", "Arial", "Courier New"]
Change "Verdana" to "Any font"
Change "Arial" to "Any font"
Change "Courier New" to "Any font"
Don't remove ""
Notebook font size
NOTEBOOK_FONT_SIZE = 20
Change 20 to any size like numbers.
Space Notebook
NOTEBOOK_WLH = 24
Change 24 to any space number.
I don't need money from you.
Dunnit.
#===============================================================================
# Notebook Menu (VXA)
# By Jet10985 (Jet) - converted to VXA by Pacman (21/10/12)
#===============================================================================
# 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.
#===============================================================================
=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 .rvdata2 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:
goto_notebook
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 (left) to scroll up, or (right) 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.
#===============================================================================
#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
# This class handles system data. It saves the disable state of saving and
# menus. Instances of this class are referenced by $game_system.
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :notebook_entries
#--------------------------------------------------------------------------
# Alias listing
#--------------------------------------------------------------------------
alias jet1835_initialize initialize
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
@notebook_entries = []
jet1835_initialize(*args, &block)
end
end
#==============================================================================
# ** Game_Interpreter
#------------------------------------------------------------------------------
# An interpreter for executing event commands. This class is used within the
# Game_Map, Game_Troop, and Game_Event classes.
#==============================================================================
class Game_Interpreter
#--------------------------------------------------------------------------
# * Add Notebook Entry to Database
#--------------------------------------------------------------------------
def add_entry(filename)
unless $game_system.notebook_entries.include?(filename)
$game_system.notebook_entries.push(filename)
end
end
#--------------------------------------------------------------------------
# * Activate Notebook Scene
#--------------------------------------------------------------------------
def goto_notebook
SceneManager.goto(Scene_Notebook)
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# This class performs the title screen processing.
#==============================================================================
class Scene_Title
#--------------------------------------------------------------------------
# Alias listing
#--------------------------------------------------------------------------
alias jet1934_initialize initialize unless $@
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
convert_txt if Notebook::DO_CONVERSION_TO_RVDATA && $TEST
jet1934_initialize(*args, &block)
end
#--------------------------------------------------------------------------
# * Convert text from .txt to .rvdata2
#--------------------------------------------------------------------------
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.rvdata2", "wb")
Marshal.dump(text_hash, b)
b.close
p "Notebook file successfully converted."
end
end
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
# The string class. Can handle character sequences of arbitrary lengths.
# See String Literals for more information.
#==============================================================================
class String
#--------------------------------------------------------------------------
# * Split to each word
#--------------------------------------------------------------------------
def each_word
array = self.split(" ")
if block_given?
array.each {|a| yield a }
else
return array
end
end
end
#==============================================================================
# ** Window_Notebook
#------------------------------------------------------------------------------
# This window displays the note currently open.
#==============================================================================
class Window_Notebook < Window_Base
#--------------------------------------------------------------------------
# Include Notebook module
#--------------------------------------------------------------------------
include Notebook
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(filename)
super(160, 56, Graphics.width - 160, Graphics.height - 56)
@filename = filename
refresh(@filename)
end
#--------------------------------------------------------------------------
# * Refresh window
#--------------------------------------------------------------------------
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
#--------------------------------------------------------------------------
# * Form Contents (or whatever)
#--------------------------------------------------------------------------
def form_bitmap_rect(filename)
if USE_RVDATA_FILE
file = load_data("Data/Notebook.rvdata2")[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
#==============================================================================
# ** Window_NoteCommand
#------------------------------------------------------------------------------
# This window is the selection window for the notebook entries.
#==============================================================================
class Window_NoteCommand < Window_Command
#--------------------------------------------------------------------------
# * Form list of commands
#--------------------------------------------------------------------------
def make_command_list
for entry in $game_system.notebook_entries
add_command(entry, :entry)
end
end
end
#==============================================================================
# ** Window_Entries
#------------------------------------------------------------------------------
# This window displays the number of entries in the notebook database.
#==============================================================================
class Window_Entries < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, Graphics.height - 54, 160, 54)
refresh
end
#--------------------------------------------------------------------------
# * Refresh window
#--------------------------------------------------------------------------
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
#==============================================================================
# ** Scene_Gameover
#------------------------------------------------------------------------------
# This class performs notebook screen processing.
#==============================================================================
class Scene_Notebook < Scene_Base
#--------------------------------------------------------------------------
# * Start Processing
#--------------------------------------------------------------------------
def start
if $game_system.notebook_entries.empty?
return_scene
end
super
@help_window = Window_Help.new
@help_window.set_text(Notebook::NOTEBOOK_NAME)
@command_window = Window_NoteCommand.new(0, 0)
@command_window.height = Graphics.height - 110
@command_window.y = @help_window.height
@entries_window = Window_Entries.new
@notebook_window = Window_Notebook.new($game_system.notebook_entries[0])
@command_window.height = Graphics.height - (@entries_window.height +
@help_window.height)
@notebook_window.y = @command_window.y
@notebook_window.height = Graphics.height - @help_window.height
end
#--------------------------------------------------------------------------
# * Frame update
#--------------------------------------------------------------------------
def update
old_index = @command_window.index
super
if old_index != @command_window.index
@notebook_window.refresh(@command_window.current_data)
end
@notebook_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
SceneManager.goto(Scene_Map)
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
end
#===============================================================================
#
# END OF SCRIPT
#
#===============================================================================
Let me know if anything's wrong. :)
I believe I know what's causing that. Go to line 322. Around here you should see the line:
@notebook_window.refresh(@command_window.current_data)
Replace that with:
@notebook_window.refresh(@command_window.current_data[:name])
That should work. Lemme know how it goes.
I believe I know what's causing that. Go to line 322. Around here you should see the line:
@notebook_window.refresh(@command_window.current_data)
Replace that with:
@notebook_window.refresh(@command_window.current_data[:name])
That should work. Lemme know how it goes.
Thanks!^_^
That got it, it's working fine now!^_^
Sorry for the late reply.
Been out sick lately y'know.
Thanks again now!^_^
I don't think I have the time or skills required to implement that. I'm not sure how to check the first letter of a string. Sorry.
Well, if x is your string, then you can check the first letter by x[0,1], but for sorting things alphabetically, it is useful to know when you check <=> as between two strings, the result is determined alphabetically, which is to say a < b < c < ... x < y < z < A < B < C < ... And it works for strings of any length, so it will sort the way you expect alphabetical sorting to work. Anyway, if you have an unsorted array of strings, ary, all you would need to do is:
ary.sort! { |a, b| a.downcase <=> b.downcase }
Alternately, you could maintain an alphabetrical list by inserting them into the appropriate place when they are first added. I think I do something similar in my Quest Journal.
I was asked by a member where to insert the code to make it alphabetical. This was my response:
If you only ever add to the notebook through the add_entry method, then you could go to that method in the script:
#--------------------------------------------------------------------------
# * Add Notebook Entry to Database
#--------------------------------------------------------------------------
def add_entry(filename)
unless $game_system.notebook_entries.include?(filename)
$game_system.notebook_entries.push(filename)
end
end
And just add the following line right after $game_system.notebook ...:
#--------------------------------------------------------------------------
# * Add Notebook Entry to Database
#--------------------------------------------------------------------------
def add_entry(filename)
unless $game_system.notebook_entries.include?(filename)
$game_system.notebook_entries.push(filename)
$game_system.notebook_entries.sort! { |a, b| a.downcase <=> b.downcase }
end
end
That said, that is a very inefficient way to do it and it could get laggy if you have tons of entries. It would be better to insert them in a sorted array to begin with.
You could do that by adding the following module into its own slot in the Script Editor:
#==============================================================================
# ** MAQJ_SortedArray
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# This module mixes in to an array to maintain the sorted order when inserting
#==============================================================================
module MAQJ_SortedArray
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Insert to Array
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def maqj_insert_sort(el, &block)
index = bsearch_index(el, 0, size, &block)
index ? insert(index, el) : push(el)
end
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Retrieve Index from Binary Search
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def bsearch_index(el, b = 0, e = size, &block)
return bsearch_index(el, b, e) { |a,b| a <=> b } if block.nil?
return b if b == e # Return the discovered insertion index
return if b > e
m = (b + e) / 2 # Get Middle
block.call(el, self[m]) > 0 ? b = m + 1 : e = m
bsearch_index(el, b, e, &block)
end
end
Then, you would need to go to the above method already mentioned and change it to:
#--------------------------------------------------------------------------
# * Add Notebook Entry to Database
#--------------------------------------------------------------------------
def add_entry(filename)
unless $game_system.notebook_entries.include?(filename)
$game_system.notebook_entries.maqj_insert_sort(filename) { |a, b| a.downcase <=> b.downcase}
end
end
And then you would need to go to the Initialize method in Game System, which should look like this:
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
@notebook_entries = []
jet1835_initialize(*args, &block)
end
You would need to change it to:
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args, &block)
@notebook_entries = [].send(:extend, MAQJ_SortedArray)
jet1835_initialize(*args, &block)
end
Those are alternatives. Do one or the other. Don't do both.
Again, either method only works if all entries to the array are added through the add_entry method in Game_Interpreter. If you add them through $game_system directly then they won't get sorted, and it is particularly troublesome to do that if you add it throught the second way.
Also, if you're already using my Quest Journal, then there is no reason to add that module in its own slot.