So I'm using [SSS] - Pick Item Event and I'm coming across this error.
It's explained only to call this item through the map. Well, I would like to call this scene through this custom Chat Menu script. I decided I'd give it a whirl, and this is the error I ran into when I tried:
Script 'Scene_Chat' line 96: NameError occurred.
undefined local variable or method 'pick_item_event' for #<Scene_Chat:0x337e168>
I understand this means the script can't see that method. But I don't see why as it's callable by a map and it is written into the game interpreter by the Pick Item Event script. (My understanding of RGSS isn't good though) It seems like this works when you assign a variable by calling the pick item event and returning it's value. Is there any easy fix?
Previous Issued SOLVED by Kread-Ex
So, I figured I'd show the class it's in and ask for some help pinpointing the issue. I'm still not familiarized with Ruby syntax, but I'm getting there. I can't detect anything wrong with line 211 and have tried backtracking over it to figure it out but to no avail.
CODE
class Window_Pick_Item_Help < Window_Base #-------------------------------------------------------------------------- # * Initialize #-------------------------------------------------------------------------- def initialize(pick_item_window) @pick_item_window = pick_item_window y = @pick_item_window.y - 56 w = [@pick_item_window.width, 200].max x = Graphics.width - w super(x, y, w, 56) self.openness = 0 refresh end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update super refresh if @last_item != @pick_item_window.item end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh self.contents.clear item = @last_item = @pick_item_window.item draw_icon(item.icon_index, 0, 0) #PROBLEM IS POINTED AT AS BEING HERE self.contents.draw_text(24, 0, contents.width - 24, WLH, item.name) end end
This is the entire script:
SSS - Pick Item
CODE
#=========================================================================== ==== # # Shanghai Simple Script - Pick Item Event # Last Date Updated: 2010.05.25 # Level: Easy # # This script prompts open a window to allow the player to select an item, # weapon, or armor from the inventory to give the NPC, show the NPC, or whatever # floats your boat. Works only on the map. #=============================================================================== # Instructions # ----------------------------------------------------------------------------- # To install this script, open up your script editor and copy/paste this script # to an open slot below ��€“� Materials but above ��€“� Main. Remember to save. # # These commands go into the script call event. Use any one of these. # $game_variables[1] = pick_item_event # $game_variables[1] = pick_weapon_event # $game_variables[1] = pick_armor_event # # This will return the selected item's item ID, weapon ID, or armor ID to the # game variable you stored. 0 is returned if the player cancels. # # <key item> # Place this tagin the noteboxes of your items, weapons, or armors to make # you unable to select those items for the pick item event. #===============================================================================
$imported = {} if $imported == nil $imported["PickItemEvent"] = true
module SSS # This sets how many items will be shown by rows and columns. PICK_ITEM_ROWS = 8 PICK_ITEM_COLS = 8 end
class RPG::BaseItem #-------------------------------------------------------------------------- # key_item #-------------------------------------------------------------------------- def key_item return @key_item if @key_item != nil @key_item = false self.note.split(/[\r\n]+/).each { |line| case line when /<(?:KEY_ITEM|key item)>/i @key_item = true end } return @key_item end end
class Window_Pick_Item < Window_Selectable #-------------------------------------------------------------------------- # * initialize #-------------------------------------------------------------------------- def initialize(type) @type = type w = SSS::PICK_ITEM_COLS * 24 + 32 x = Graphics.width - w h = [SSS::PICK_ITEM_ROWS * 24 + 32, Graphics.height - 184].min y = Graphics.height - h - 128 super(x, y, w, h) self.index = 0 self.openness = 0 @column_max = SSS::PICK_ITEM_COLS @spacing = 0 refresh end #-------------------------------------------------------------------------- # * Item #-------------------------------------------------------------------------- def item return @data[self.index] end #-------------------------------------------------------------------------- # * Refresh #-------------------------------------------------------------------------- def refresh @data = [] case @type when :item, :items for item in $game_party.items next unless item.is_a?(RPG::Item) @data.push(item) if include?(item) end when :weapon, :weapons for item in $game_party.items next unless item.is_a?(RPG::Weapon) @data.push(item) if include?(item) end when :armor, :armors, :armour, :armours for item in $game_party.items next unless item.is_a?(RPG::Armor) @data.push(item) if include?(item) end end @item_max = @data.size create_contents for i in 0...@item_max draw_item(i) end end #-------------------------------------------------------------------------- # * Include? #-------------------------------------------------------------------------- def include?(item) return false if item.nil? return true end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item(index) rect = item_rect(index) self.contents.clear_rect(rect) item = @data[index] unless item.nil? icon = item.icon_index draw_icon(icon, rect.x, rect.y, enabled?(item)) draw_item_amount(item, rect.clone) end end #-------------------------------------------------------------------------- # * Enabled? #-------------------------------------------------------------------------- def enabled?(item) return false if item.nil? return false if item.key_item return true end #-------------------------------------------------------------------------- # * Draw Item Amount #-------------------------------------------------------------------------- def draw_item_amount(item, rect) self.contents.font.size = 12 number = $game_party.item_number(item) self.contents.font.color.alpha = enabled?(item) ? 255 : 128 self.contents.draw_text(rect.x, rect.y + WLH/3, 24, WLH * 2/3, number, 2) end end
class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # * Termination Processing #-------------------------------------------------------------------------- alias terminate_sss_pick_item_event terminate unless $@
def terminate unless @pick_item_window.nil? @pick_item_window.dispose @pick_item_window = nil @pick_item_help.dispose @pick_item_help = nil end terminate_sss_pick_item_event end #-------------------------------------------------------------------------- # * Pick Item Event #-------------------------------------------------------------------------- def pick_item_event(type = :item) case type when :item, :items, :weapon, :weapons, :armor, :armors, :armour, :armours @pick_item_window = Window_Pick_Item.new(type) @pick_item_help = Window_Pick_Item_Help.new(@pick_item_window) else return 0 end value = 0 @pick_item_window.open @pick_item_help.open loop do update_basic @pick_item_window.update @pick_item_help.update if Input.trigger?(Input::cool.gif) Sound.play_cancel value = 0 break elsif Input.trigger?(Input::C) item = @pick_item_window.item if @pick_item_window.enabled?(item) Sound.play_decision value = item.id break else Sound.play_buzzer end end end @pick_item_window.close @pick_item_help.close loop do update_basic @pick_item_window.update @pick_item_help.update break if @pick_item_window.openness == 0 end @pick_item_window.dispose @pick_item_window = nil @pick_item_help.dispose @pick_item_help = nil return value end end
#=============================================================================== # # END OF FILE # #===============================================================================
This post has been edited by Titanhex: Jul 13 2011, 06:00 AM
Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed
This means the item is nil. I don't see why, though, but you could avoid the issue by placing return if item == nil just below item = @last_item = @pick_item_window.item.
__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.
Thank you Kread-Ex. That solved the problem perfectly and the script seems to work. (Though it's def. not plug & play) I think I've learned a little bit more (& remembered some scripting solutions) about getting scripts to work.
I have another issue with getting the script to work for my needs and modified the first post to update this and cut down on board clutter.
This post has been edited by Titanhex: Jul 12 2011, 02:43 PM
Group: +Gold Member
Posts: 4,136
Type: Scripter
RM Skill: Undisclosed
Let's look at the pick_item_event method:
CODE
def pick_item_event return 0 unless $scene.is_a?(Scene_Map) return $scene.pick_item_event(:item) end
Basically, if you are using a call script event command, the interpreter will trigger another pick_item_event, defined in the map scene. If you want to call this method from another scene, you need to copy the method from the map in your new scene.
__________________________
FRACTURE - a SMT inspired game (demo) made by Rhyme, Karsuman and me. Weep and ragequit.
I did notice that the $scene.pick_item_event(:item) does seem to be referencing itself, which I imagine isn't the case, so it makes sense now that you mention it's pointing to another method of pick_item_event.
Also, despite the fact that my head hurts, I am beginning to understand what some of this stuff is doing. I got the rest of it to work
This post has been edited by Titanhex: Jul 13 2011, 05:59 AM