Can Some one help me out? Making my own shop

First, let me apologize for all the threads. I am not a novice programmer, nor new to ruby (I did rails, and I am a software developer by trade). With that said, I have never "scripted" before and I have never worked with RGSS, it does seem easy to pick up, how ever if that were the case I wouldn't be here asking for help.

Let get on with it.

I have attempted to create a shop, this shop is going to use a specific currency. I wanted to understand the way the shop classes, scenes, windows and such worked so I attempted to go out and create my own. I am no where near it though. Thus I need your help.

Note: This script is based of, Tsukihime, http://dl.dropboxusercontent.com/u/23043573/RPG%20Maker/RMVXA%20Scripts/Shop_Manager.txt

Couple of issues:

  • put @inventory.inspect will give me [[#<ClassObject>, #<ClassObject>], [#<ClassObject>, #<ClassObject>]] instead of the items.
  • when calling the scene to init the shop, I get an error on make_item_list, stating that .each doesn't exist. essentially it cant walk through an empty array.
This script composes of a series of classes that extend the parent, thus to reduce the need to re-write everything, but also allowing me to over ride, or use specific parent methods, with out the harm to other scripts that alias such methods. I thought this was the best approach.
This script, for the time being, is called as such:

## Create your items$kc_shop.create_master_inventory(1, 1, 1, 10) #id (unique), #item_type, #item_id, #price$kc_shop.create_master_inventory(2, 1, 2, 10) #id (unique), #item_type, #item_id, #price ## Open the shop windowGS.call_shop(GS.setup($kc_shop.get_inv)) #call the shop while passing the master inventory list to the shop window. There are things that I am missing in the main script and some naming issues have arisen (such as how I name things, not compilation errors), I understand that. How ever The main issue I am trying to solve, aside from those out lined in the list above is why I am getting: undefined each for Nil:NilClass. 

Its obvious to me, The inventory list is not being passed to the window, yet I assumed I took care of that in the GS.call_shop() method.

Note: This script is documented, how ever not deeply, near the end there is no documentation. I have created my own object for dealing with items called: Game_Guild_ShopObject

Spoiler
module GS  def self.setup(goods, purchase_only = false)    shop = Game_Guild_Shop.new(goods, purchase_only)  end    def self.call_shop(shop)    SceneManager.call(Scene_Guild_Shop)    SceneManager.scene.prepare(shop)  endend #==============================================================================# ** DataManager#------------------------------------------------------------------------------#  Create a new object called $kc_shop.#==============================================================================class << DataManager    #--------------------------------------------------------------------------    # * Create Game Objects    #--------------------------------------------------------------------------    alias kalacious_guild_shop_game_objects create_game_objects    def create_game_objects      kalacious_guild_shop_game_objects      $kc_shop = Game_Guild_ShopSetup.new    endend #==============================================================================# ** Game_Guild_ShopSetup#------------------------------------------------------------------------------#  Helps to set up the core shop it's self.#==============================================================================class Game_Guild_ShopSetup     attr_accessor :inventory_list    #--------------------------------------------------------------------------  # * Set up an empty array of inventory items  #--------------------------------------------------------------------------    def initialize    @inventory_list = []  end   #--------------------------------------------------------------------------  # * Create a master inventory list.  #--------------------------------------------------------------------------    def create_master_inventory(id, item_type, item_id, item_price)    inventory = make_inventory(id, item_type, item_id, item_price)    @inventory_list.push(inventory)  end    #--------------------------------------------------------------------------  # * Retieve the object.  #--------------------------------------------------------------------------  def get_inv    return @inventory_list  end    #--------------------------------------------------------------------------  # * Make the inventory.  #--------------------------------------------------------------------------  private  def make_inventory(id, item_type, item_id, item_price)    inventory = Game_Guild_ShopObject.new(id, item_type, item_id, item_price)    return inventory  endend  #==============================================================================# ** Game_Guild_ShopObject#------------------------------------------------------------------------------#  This class is a wrapper for how the shops object stores the data about#  the items in the shop.#==============================================================================class Game_Guild_ShopObject    attr_reader :id  attr_reader :item_type  attr_reader :item_id  attr_reader :item_price    #--------------------------------------------------------------------------  # * Set up the objects  #--------------------------------------------------------------------------  def intialize(id, item_type, item_id, item_price)    @id = id    @item_type = item_type    @item_id = item_id    @item_price = item_price  end    #--------------------------------------------------------------------------  # * Return the $data_item, $data_weapons or $data_armor based on the id and  #   the type.  #--------------------------------------------------------------------------    def guild_shop_item    return $data_items[@item_id] if @item_type == 0    return $data_weapons[@item_id] if @item_type == 1    return $data_armor[@item_id] if @item_type == 2  end    #--------------------------------------------------------------------------  # * Return the price.  #--------------------------------------------------------------------------  def get_guild_shop_price    return @price  endend #==============================================================================# ** Game_Game_Shop#------------------------------------------------------------------------------#  This class is responsible for dealing with the inventory of a guild shop.#  That is, we deal with the abillity to purchase only, the inventory, in #  regards to adding and deleting items and the abillity to, or the need for,#  the shop to be refreshed.#==============================================================================class Game_Guild_Shop    attr_reader 😛urchase_only  attr_reader :inventory  attr_accessor :refresh    #--------------------------------------------------------------------------  # * Set up the core shop.  #--------------------------------------------------------------------------    def initialize(goods, purchase_only = false)    @purchase_only = purchase_only    @inventory = goods    @refresh = false  end    #--------------------------------------------------------------------------  # * Return the inventory.  #--------------------------------------------------------------------------    def get_guild_shop_inventory    return @inventory  end    #--------------------------------------------------------------------------  # * Add a new item.  #--------------------------------------------------------------------------    def add_item(item)    @inventory.push(item) unless @inventory.include? (item)  end    #--------------------------------------------------------------------------  # * Delete an item based on id.  #--------------------------------------------------------------------------    def delete_item(item_id)    @inventory.delete_at(item_id-1)  endend   class Window_Guild_Shop_Buy < Window_ShopBuy    def get_current_item    @inventory[item]  end    def make_item_list    @data = []    @items = {}    @price = {}    @inventory.each do |inventory|      item = inventory.item      @data.push(item)      @items[item] = inventory      @prive[item] = inventory.price    end  endend class Scene_Guild_Shop < Scene_Shop    def prepare(goods, purchase_only = false)    super    @inventory = goods    @purcahse_only = purchase_only  end    def create_buy_window    wy = @dummy_window.y    wh = @dummy_window.height    @buy_window = Window_Guild_Shop_Buy.new(0, wy, wh, @goods)    @buy_window.viewport = @viewport    @buy_window.help_window = @help_window    @buy_window.status_window = @status_window    @buy_window.hide    @buy_window.set_handler🙂ok,     method🙂on_buy_ok))    @buy_window.set_handler🙂cancel, method🙂on_buy_cancel))      end    end
Your help and patience are much appreciated. I believe I am some where close to being on the right tack. I did not use Tsukihime's script, when it might be apparent too because I did not want to risk using other shop scripts and them being affected, while I don't believe his would cause conflicts, the purpose of this was to learn on my own how to create objects, pass the around and create my own shop while using core resources.
The default scripts in the engine have taken the idea of modular programming to such an extreme that I would call it "fragmented programming" ;-)

As a result, the error given by the standard game engine is often misleading as it tells of the last part where the error was detected, not alwqays the place where it occured - especially in the case of those "undefined for Nil" errors.

I would suggest using the backtracer script to check if the error really is at the place reported or if it comes from another area.

http://himeworks.wordpress.com/2013/06/09/custom-main-full-error-backtrace/
Oh I know exactly where the error is occurring, apologizes if that was not made clear. Let me post that. In this class:

class Window_Guild_Shop_Buy < Window_ShopBuy def get_current_item @inventory[item] end def make_item_list @data = [] @items = {} @price = {} @inventory.each do |inventory| item = inventory.item @data.push(item) @items[item] = inventory @prive[item] = inventory.price end endendThe error happens at @inventory.each, where each is spazzing out, because as stated, @inventory is nill. Now when I passed in the inventory object by doing:

Code:
## Open the shop windowGS.call_shop(GS.setup($kc_shop.get_inv)) #call the shop while passing the master inventory list to the shop window.
I assumed I passed inventory to the prepare statement, thus preparing the shop to render the objects in the window. Apparently not, but i cant figure out whats stopping it from being passed. Hence why a second set of eyes to be like "you tool, you doing this wrong, silly troll."But ill try out this script and see if it makes a difference in telling me what I am doing wrong.

Update

I may have figured it out, the object I am passing is:

296

#<Game_Guild_Shop:0x99f6984 @purchase_only=false, @inventory=[#<Game_Guild_ShopO

bject:0x99f69ac>, #<Game_Guild_ShopObject:0x99f6998>], @refresh=false>

If some one can explain why I am getting: #<Game_Guild_ShopObject:0x99f6998> instead of what's inside of it, that would be great. Thanks.
What is it supposed to say? Or, what do you want to see?
thread can be closed, I figured it out. I re-wrote the whole thing from the ground up and it works as it should. thank you
What was the problem?
the problem was one, I don't know how to spell half the time. so it wasn't passing objects, well it was, but it wasn't. initialize is not spelled intialize. Also I needed to change the way I was working with objects. To make sure what I was passing was what I wanted. Suffice to say the only bug I have now is that if you have a choice of "shop A or Shop B" (shop B being the custom built shop), and you visit shop B, then go to Shop A and then back, B's items are doubled.

Not sure if I should fix this, since the script is meant to be used to create one shop, how ever peoples NPC's may have multiple types of shops. Regular default types and then my custom one.
It would be a good exercise to come up with a solution.


It may also improve your design.


But if you've got lots of stuff to do and it's not a bug you're going to run into yourself, AND it's not going to be released or anything...I don't think it is that important.


I mean, bugs are only problems if people run into them right............lol terrible philosophy. I wouldn't leave known bugs lying around for the most part.
It was a problem, I plan to release it and it was fixed 😀 It was a issue in making an inventory list. I was not checking if that item existed or not, hence the duplication.

The script uses my own object, I find a bit simpler then yours, each to their own though. And it uses my new currency.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/can-some-one-help-me-out-making-my-own-shop.15371/