Okay so these questions revolve around my Scene_Item script as the title states.
■ The first question I have is with case statements in Window_ItemList and Window_ItemType. For some reason instead of going through each when clause it skips over them and goes straight for the else. Just in case that doesn't make sense here's an example
example:
when :all
case @types_window.method
when :item then return item.is_a?(RPG::Item) if $game_temp.in_battle
when :weapons then return item.is_a?(RPG::Weapon)
else return item.is_a?(RPG::Armor)
end
end
In this example, no matter which category I'm in (Item, Armor, Weapon), it will always show just show all armor instead of all items if I'm under the Item category. So how do I fix that.
■ Second question/issue I'm having is adding a tag after the name in the item, weapon, and armor categories. In the module I have a hash that I'm using to create categories:
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# ■ Module ACE::CORE
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module ACE::CORE
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# ◆ Section III. Item Type Settings ◆
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# These arrays adjusts and shows the various item types shown for Items,
# Weapons, and Armours. Note that when using :category symbols, the
# specific category shown will be equal to the text used for the Display
# and the included item must contain a category equal to the Display name.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# This array contains the order for the Item categories.
ITEM_TYPES =[
# [ :symbol, "String"],
[ :usable, 'Usable'], # Shows
[ :field, 'Field'], # Shows Menu-usable items.
[ :battle, 'Battle'], # Shows Battle-usable items.
[:category, 'Special'], # Categorized by \cat[string]
[:category, 'Food'], # Categorized by \cat[string]
[:key_item, 'Key Item'], # Shows all key items.
[ :all, 'All'], # Shows all usable items.
] # Do not remove this.
# This array contains the order for the Weapon categories.
WEAPON_TYPES =[
# [ :symbol, "String"],
[:category, 'Training'], # Categorized by \cat[string]
[:category, 'Legendary'], # Categorized by \cat[string]
[ :all, 'All'], # Shows all weapons.
] # Do not remove this.
# This array contains the order for the Armour categories.
ARMOUR_TYPES =[
# [ :symbol, "String"],
[ :kind, 'ARMKIND'], # Lists all of the individual armour kinds
[:category, 'Training'], # Categorized by \cat[string]
[:category, 'Legendary'], # Categorized by \cat[string]
[ :all, 'All'], # Shows all armours.
] # Do not remove this.
end
What I was trying to do is when an Item has the tag \cat[string] after the item name, the item should appear in its respective category. It's just bad coding in Window_ItemList and the RPG module and I have no clue how to fix that.
Hopefully these two questions make sense if you need any clarifications just ask and heres the script:
http://db.tt/OFybzF5z (http://Item Scene)
Here I come, back to the rescue :P
The link you provided is not working so I'll post typical answers.
1.) If it is skipping to the 'else', obviously @types_window.method is not returning the symbols :item or :weapons. From you previous scripts, I recalled #method returning an integer value. Put a print method before evaluating the case and see what's going on.
2.) It's probably because the item/weapon/armor is now named 'Database_Name \\cat[name]' or the name isn't even being changed at all? I'd need to see what is the exact problem.
How about now
Item Scene (http://db.tt/OFybzF5z)
Note: you'll notice that I'll have a something else as well for the Tags in the RPG module as I was testing different stuff.
Alright, I have a feeling I got it all down. Let's first talk about Window_ItemList#ace_item_include?(item).
The first issue, as you pointed out, was that when viewing :all, it would always draw all armors regardless of the category. Thus @types_window.method was not returning :items or :weapons. By using a print method, I was able to see that @types_window.method was actually returning
the exact same symbol as @category was. @types_window contains the items 'Usable, Field, Battle, etc.', but you wanted the window that has the items 'Items, Weapons, Armors'. I'm guessing you wanted to use Window_ItemCommand.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# ■ Window_ItemList
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
class Window_ItemList < Window_Item
include ACE::CORE
def initialize(y, height)
super(0, y, 640, height)
deactivate
@category = :none
@ext = :none
@name = ""
end
def category=(category)
if @types_window.nil?
return if @category == category
@category = category
refresh
self.oy = 0
else
return unless update_types?(category)
@category = category
if @types_window.active
@name = @types_window.commands
@ext = @types_window.method
end
refresh
self.oy = 0
end
end
def update_types?(category)
return true if @category != category
return false unless @types_window.active
return @name != @types_window.commands if category == :category
return @ext != @types_window.method
end
def types_window=(window)
@types_window = window
end
# Kk20 : New method. Called in Scene_Item#create_item_window
def category_window=(window)
@category_window = window
end
def include?(item)
return false if item.nil?
@types_window.nil? ? old_item_include?(item) : ace_item_include?(item)
end
def old_item_include?(item)
case @category
when :items then item.is_a?(RPG::Item)
when :weapons then item.is_a?(RPG::Weapon)
when :armor then item.is_a?(RPG::Armor)
else false
end
end
#KK20
# Editted with category_window instead of types_window
def ace_item_include?(item)
# @category is equal to @types_window.method
case @category
when :usable then item.is_a?(RPG::Item) && item.usable_ok?
when :field
return false unless item.is_a?(RPG::Item)
return false if item.battle_ok?
return item.menu_ok?
when :battle
return false unless item.is_a?(RPG::Item)
return false if item.menu_ok?
return item.battle_ok?
when :key_item then item.is_a?(RPG::Item) && item.key_item?
#---
when :shield then item.is_a?(RPG::Armor) && item.shield?
when :helmet then item.is_a?(RPG::Armor) && item.helmet?
when :body_armor then item.is_a?(RPG::Armor) && item.body_armor?
when :accessory then item.is_a?(RPG::Armor) && item.acessory?
#---
when :all
#KK20
# :item => :items
# :weapon => :weapons
case @category_window.method
# No idea why 'if $game_temp.in_battle' is there...
when :items then return item.is_a?(RPG::Item) #if $game_temp.in_battle
when :weapons then return item.is_a?(RPG::Weapon)
else return item.is_a?(RPG::Armor)
end
#---
#KK20
# When viewing 'Food', for example, @category was returning :food (not :category)
# Thus, this is the new 'else' condition
#when :category
else
case @category_window.method
when :items then return false unless item.is_a?(RPG::Item)
when :weapons then return false unless item.is_a?(RPG::Weapon)
else return false unless item.is_a?(RPG::Armor)
end
# If the item has a category and it matches the category you want to view
if !item.category.nil? && item.category.include?(@category.to_s)#.upcase)
return true
else # The original 'else' condition you had before
return old_item_include?(item)
end
#---
#else
# return old_item_include?(item)
end
end
def select_last
select(@data.size - 1) if item.id == $game_party.last_item_id
select([self.index, 0].max)
end
def make_item_list
$game_party.items.each {|item| next unless include?(item); @data << item}
end
def draw_item(index)
rect = item_rect(index)
contents.clear_rect(rect)
item = @data[index]
return if item.nil?
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item), rect.width - 24)
contents.draw_text(rect, sprintf(':%2d', $game_party.item_number(item)), 2)
end
end
I've commented areas with 'KK20' to mark changes and additions I made.
I also noticed that, after selecting "Weapons", you would not be shown the right subcategories. I made this change to Window_ItemType
def reveal(type)
@type = type
# KK20==================
array = make_command_list
@data = array[1]
commands = array[0]
@item_max, @commands = commands.size, commands
# KK20==================
refresh
activate
select(0)
end
As for the RPG::Item issue, I did this:
def name
return @name.gsub(/\\category\[(\w+)\]/) {""}
end
def category
@category = []
@name.downcase.gsub!(/\\category\[(\w+)\]/) do
return @category = $1.to_s
end
end
I'm not super experienced with Regexp yet, but this looked good to me.
So what is this now...? Like the 10th time I've helped you with your scripts? =P
Quote from: KK20 on April 14, 2013, 09:55:18 pm
I also noticed that, after selecting "Weapons", you would not be shown the right subcategories. I made this change to Window_ItemType
def reveal(type)
@type = type
# KK20==================
array = make_command_list
@data = array[1]
commands = array[0]
@item_max, @commands = commands.size, commands
# KK20==================
refresh
activate
select(0)
end
You know I thought of something like this, didn't know where to put it, got frustrated and gave up for the time being. Thanks for clearing that up.
Quote from: KK20 on April 14, 2013, 09:55:18 pm
As for the RPG::Item issue, I did this:
def name
return @name.gsub(/\\category\[(\w+)\]/) {""}
end
def category
@category = []
@name.downcase.gsub!(/\\category\[(\w+)\]/) do
return @category = $1.to_s
end
end
I'm not super experienced with Regexp yet, but this looked good to me.
Regexp is just too confusing sometimes, I wish RMXP had noteboxes like VX/VXA as it would make life easier instead of putting the tag in the name box. Doesn't seem like a good place to put it. Anyways thanks for the help again, I appreciate it. :^_^':
If you have problems with regexps, then try rubular (http://www.rubular.com). It has a reference to all the different codes you can use in regular expressions and you can test regular expressions to see if they match things correctly. That's what I use whenever something isn't getting matched by my regexps.
Quote from: ThallionDarkshine on April 15, 2013, 07:49:29 am
If you have problems with regexps, then try rubular (http://www.rubular.com). It has a reference to all the different codes you can use in regular expressions and you can test regular expressions to see if they match things correctly. That's what I use whenever something isn't getting matched by my regexps.
Thank that will be real helpful in the future. +1 to both of you for awesomeness ;)