Shop Steal free buy problem

This should (and hopefully) be the last Shop Steal problem I have.
So as you might know, I'm a amateur at coding, but I can still figure things out (RUBY can make so many more problems)
The problem is that when buying stuff, the items are free when the window opens.
The script only adds code, so I don't know what happened. Here's the bit of code that I think might be the problem (it's basically a modified copy of Window_ShopBuy)
Code:
#==============================================================================
# ** Window_ShopSteal
#------------------------------------------------------------------------------
#  This window displays a list of steal goods on the shop screen.
#==============================================================================

class Window_ShopSteal < Window_Selectable
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader   :status_window            # Status window
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x, y, height, shop_goods)
    super(x, y, window_width, height)
    @shop_goods = shop_goods
    @money = 0
    refresh
    select(0)
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 304
  end
  #--------------------------------------------------------------------------
  # * Get Number of Items
  #--------------------------------------------------------------------------
  def item_max
    @data ? @data.size : 1
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    @data[index]
  end
  #--------------------------------------------------------------------------
  # * Set Party Gold
  #--------------------------------------------------------------------------
  def money=(money)
    @money = money
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Price of Item
  #--------------------------------------------------------------------------
  def price(item)
    @price[item]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    make_item_list
    create_contents
    draw_all_items
  end
  #--------------------------------------------------------------------------
  # * Create Item List
  #--------------------------------------------------------------------------
  def make_item_list
    @data = []
    @price = {}
    @shop_goods.each do |goods|
      case goods[0]
      when 0;  item = $data_items[goods[1]]
      when 1;  item = $data_weapons[goods[1]]
      when 2;  item = $data_armors[goods[1]]
      end
      if item
        @data.push(item)
        @price[item] = goods[2] == 0 ? item.price : goods[3]
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
    item = @data[index]
    rect = item_rect(index)
    draw_item_name(item, rect.x, rect.y)
    rect.width -= 4
    draw_text(rect, price(item), 2)
  end
  #--------------------------------------------------------------------------
  # * Set Status Window
  #--------------------------------------------------------------------------
  def status_window=(status_window)
    @status_window = status_window
    call_update_help
  end
  #--------------------------------------------------------------------------
  # * Update Help Text
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_item(item) if @help_window
    @status_window.item = item if @status_window
  end
end

I'm just looking for ways to fix the problem, not necessarily asking for someone to find out for me; I still want to improve, and possibly say that I made this script.
If more is needed, I will supply it.
Maybe you need to change
@price = {}
to
@price = []
Maybe you need to change
@price = {}
to
@price = []
That didn't work. It crashed the game because there was no number.
what exactly are you trying to accomplish here?
what exactly are you trying to accomplish here?
I am trying to make a new mechanic that allows you to steal from any shop.
All I need to do is fix a bug where you get one free item from the buy window whenever it's opened, allowing infinite items.
Once this one bug is fixed, it's ready for me and others to properly use. I really want to make this new gameplay feature, though I don't like having to ask for help whenever RUBY refuses to cooperate, but I have to if I want to get anywhere. Though I'm fine with asking where to start a project.
I don't really see any problems with the window itself.
where are you calling it *from*?
I don't really see any problems with the window itself.
where are you calling it *from*?
If you mean by where it's activated, I use Scene_Shop.
I put it with the Buy and Sell commands, though I mostly copy and pasted the Buy definitions and replaced Buy with Steal.
Do you think you need Scene_Shop's code to find the problem?
so, "steal" is a feature within the standard Scene_Shop, which you say you didn't modify except for adding the "steal" option.

*what* is not working?
so, "steal" is a feature within the standard Scene_Shop, which you say you didn't modify except for adding the "steal" option.

*what* is not working?
The buy option is not working right, but steal and sell works perfectly fine.
The problem with buy is that it's letting the player take one of any item when you open the buy option, regardless of how much money you have. It corrects itself when you take an item, however goes back when buy is selected. It will take away the required money, but you will still get the item if it's at 0.

Players can abuse this by repeatedly reopening the buy menu after taking the free item.
if opening the shop leads into the buy option directly, then you have a problem with the shop *scene* not setting up correctly.
it's supposed to open, hold for command, hold for category, and then open the window for selection.
and, the command is handled by the command window, which then releases control to the scene which then releases control to the category window, WHICH then gives control back to the scene, and the scene moves it to the item window.

Disable your window and put things back as they were, and map what is going where, and when. Then, add your window back.
looks like a flow problem, not a window problem.
if opening the shop leads into the buy option directly, then you have a problem with the shop *scene* not setting up correctly.
it's supposed to open, hold for command, hold for category, and then open the window for selection.
and, the command is handled by the command window, which then releases control to the scene which then releases control to the category window, WHICH then gives control back to the scene, and the scene moves it to the item window.

Disable your window and put things back as they were, and map what is going where, and when. Then, add your window back.
looks like a flow problem, not a window problem.
Thank you SO MUCH!
I managed to find the problem. Several areas I accidentally deleted, and replaced them with the steal functions. Don't ask me how that happened, I'm just as clueless as you.
Now that the script is functionally perfected, I'm going to post it in some places.
I had my fair share of headaches with that sequence.

Original thread: https://forums.rpgmakerweb.com/threads/shop-steal-free-buy-problem.104930/