This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
Introduction
This tool allows you to tag sections of your Note fields with whatever pair of substrings you want, cutting out what's between those tags and returning it for you to save as a new variable, evaluate, or whatever else you can think of.
Features
* Cuts the listed pair of tags out of a Note field, along with everything between them.
* Trims the tagged section and what's left of the Note field of whitespace at the front and back.
* Returns what was between the tags, discarding the tags themselves.
Script
The Script
Code:
#==============================================================================
# Note Dissection
#------------------------------------------------------------------------------
# Provided by DrakoShade
# 23 March, 2008
#==============================================================================
=begin
This script does absolutely nothing but slow down the loading of the database,
if it's on its own. It's a tool, for use by other scripters who think that
the Note field is a great place to insert data or code.
RPG::Skill, RPG::Item, RPG::Weapon, RPG::Armor, RPG::Enemy, and RPG::State all
have two new methods. They're exactly the same in all six cases.
dissect_note does nothing. It exists to be aliased and added to. Anything
you add to it will be run by each individual example of the class to which
it was added when the database is loaded.
myslice! destructively chops out a tagged section of the Note field and,
cleaning the tags and everything between them out of the Note then returning
only what was between the tags. The tags themselves disappear, so neither
the Note nor whatever is returned will contain them.
Here's an example of how it might be used:
#==============================================================================
# ** Testfoo Example Script
#==============================================================================
#module RPG
# class Item
# attr_accessor :testfoo
# alias drakoshade_testfoo_item_dissect_note dissect_note
# def dissect_note
# drakoshade_testfoo_item_dissect_note
# @testfoo = myslice!("startfoo", "endfoo")
# end
# end
#end
#==============================================================================
# End example.
#==============================================================================
If this example is placed within your scripts, UNDER Script Dissection, then
you will be able to access $data_items[x].note and $data_items[x].testfoo as
completely separate variables, both unique to the individual item in question.
With all that said, here's the actual script.
=end
#==============================================================================
# ** Module RPG
#------------------------------------------------------------------------------
# This script accesses six classes within the module, adding two new methods
# to each.
#==============================================================================
module RPG
#==============================================================================
# ** Class RPG::Skill
#------------------------------------------------------------------------------
# This class defines your skills. Instances of this class are called in-game
# with $data_skills.
#==============================================================================
class Skill
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_skill_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
#==============================================================================
# ** Class RPG::Item
#------------------------------------------------------------------------------
# This class defines your items. Instances of this class are called in-game
# with $data_items.
#==============================================================================
class Item
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_item_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
#==============================================================================
# ** Class RPG::Weapon
#------------------------------------------------------------------------------
# This class defines your weapons. Instances of this class are called in-game
# with $data_weapons.
#==============================================================================
class Weapon
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_weapon_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
#==============================================================================
# ** Class RPG::Armor
#------------------------------------------------------------------------------
# This class defines your armor. Instances of this class are called in-game
# with $data_armors.
#==============================================================================
class Armor
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_armor_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
#==============================================================================
# ** Class RPG::Enemy
#------------------------------------------------------------------------------
# This class defines your enemies. Instances of this class are called in-game
# with $data_enemies.
#==============================================================================
class Enemy
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_enemy_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
#==============================================================================
# ** Class RPG::State
#------------------------------------------------------------------------------
# This class defines your states. Instances of this class are called in-game
# with $data_states.
#==============================================================================
class State
#-----------------------------------------------------------------------
# * Dissect Note
# This method is empty by default. Here, you can add the chunks
# of code that you want each individual Skill to run at startup.
# It is recommended that you use the following syntax to modify
# dissect_note:
# alias yourname_scriptname_state_dissect_note dissect_note
#----------------------------------------------------------------------
def dissect_note
end
#----------------------------------------------------------------------
# * Myslice!
# begin_tag is a small substring within @note that you want to
# look for, after which the cuts begin.
# end_tag is a second substring within @note that denotes the
# end of the section you want to cut out.
# Both tags will be discarded. @note will be cleaned up, and
# this method will return what was between the tags.
#----------------------------------------------------------------------
def myslice!(begin_tag, end_tag)
tagged_section = @note[/(?<=#{begin_tag})(.*?)(?=#{end_tag})/m]
@note.slice!(begin_tag + tagged_section.to_s + end_tag)
@note.strip!
return tagged_section.to_s.strip
end
end
end
#==============================================================================
# ** Scene_Title
#------------------------------------------------------------------------------
# In order to do anything useful with our new myslice! method and the
# dissect_note method, they do have to be called. I've chosen to do so when
# the database is first loaded. It does add six loops to the loading process,
# which slows it down (especially if you have a lot of items in your database.)
#
# Every single skill, item, weapon, armor, enemy, and state is going to run
# its respective dissect_note method.
#==============================================================================
class Scene_Title
#-------------------------------------------------------------------------
# * Load the Database
# Aliased to split the notes after loading everything else.
#-------------------------------------------------------------------------
alias note_dissection_load_database load_database
def load_database
note_dissection_load_database
split_notes
end
#-------------------------------------------------------------------------
# * Load the Battle-Test Database
# Same as above.
#-------------------------------------------------------------------------
alias note_dissection_load_bt_database load_bt_database
def load_bt_database
note_dissection_load_bt_database
split_notes
end
#------------------------------------------------------------------------
# * Split Notes
# Here's all those loops. This method is necessary for all your
# tagged @note fields to be broken into their smaller variables.
#------------------------------------------------------------------------
def split_notes
for i in 1...$data_skills.size
$data_skills[i].dissect_note
end
for i in 1...$data_items.size
$data_items[i].dissect_note
end
for i in 1...$data_weapons.size
$data_weapons[i].dissect_note
end
for i in 1...$data_armors.size
$data_armors[i].dissect_note
end
for i in 1...$data_enemies.size
$data_enemies[i].dissect_note
end
for i in 1...$data_states.size
$data_states[i].dissect_note
end
end
end
Instructions
Installation: Paste this script between "▼ Materials" and any custom scripts that are likely to use it.
Usage instructions are included in the script itself.
Compatibility
Instances without a tag pair you've set to cutout will now have a blank string "" stored in the variable, rather than NIL. This was to evade some errors I found in testing.