VXAce ItemList skipping index...

I ve been working on a script of mine and trying to mimic a little bit the shopBuy Scene window.
The script is relatively simple and made to manage 2 inventories

One help window
One command window + one side panel that display weight for my compact inventory
One item category window
One ItemList (base inventory) + one ItemList (compact inventory)

I havnt change much of the class, just trying to make a transfer screen....

somehow, I cant seem to make the transfer work.
First, it seems like the index for the inventory are messed up;
Unless I hold the key DOWN or UP, the selection box in missing one entry (ex.: going from item 1 to item 3)
Second, the quantities transfered in the compact inventory is wrong....
If in the left inventory I have 10 healing potion and I transfer 1,
I get healing potion X9 - healing potion X9
If I transfer another one
healing potion X8 - healing potion X8

Anyone can help out ?


Ruby:
# Script for RPG Maker VX ACE
# Name : Weight Inventory
# Author: YourNameHere
# Version: 1.0
# Description: Adds a second inventory(compact) with weight tracking.
#              Uses Fortitude (Luck) to define inventory maximum capacity.
# Usage: Add `<Weight: X>` notetags to items. Toggle system with switch ID 100.
#        If item weight not define, default value is 1.

module WeightInventoryConfig
  TOGGLE_SWITCH_ID = 100          # Control Switch ID to activate system
  ITEM_WEIGHT_TAG = "Weight"      # Notetag for item weight
end

#  Weight Calculation Utilities
module WeightUtils
  def current_weight
    $game_party.items.inject(0) { |sum, i| sum + item_weight(i) * $game_party.item_number(i) }
  end

  def compact_weight
    return 0 unless $game_party.compact_inventory
    $game_party.compact_inventory.inject(0) { |sum, item|
      sum + item_weight(item) * $game_party.compact_item_number(item)
    }
  end

  def compact_weight_limit
    $game_party.members.inject(0) { |sum, actor| sum + actor.luk }
  end

  def item_weight(item)
    return 1 unless item && item.note
    note = item.note.match(/<#{WeightInventoryConfig::ITEM_WEIGHT_TAG}:\s*(\d+)>/)
    note ? note[1].to_i : 1
  end
end

#  Game_Party Extensions
class Game_Party < Game_Unit
  attr_accessor :compact_inventory

  alias :init_compact_inventory :initialize
  def initialize
    init_compact_inventory
    @compact_inventory = []
  end

  def compact_inventory
    @compact_inventory ||= []
  end
 
  def add_to_compact(item, amount = 1)
    amount.times { @compact_inventory << item }
  end

  def remove_from_compact(item, amount = 1)
    amount.times { @compact_inventory.delete_at(@compact_inventory.index(item) || @compact_inventory.length) }
  end

  def compact_item_number(item)
    @compact_inventory.count(item)
  end

  def items_to_transfer
    @items_to_transfer ||= []
  end

  def mark_for_transfer(item)
    items_to_transfer << item unless items_to_transfer.include?(item)
  end

  def unmark_for_transfer(item)
    items_to_transfer.delete(item)
  end
end

# * Windows
#--------------------------------------------------------------------------
class Window_TransferActions < Window_HorzCommand
  include WeightUtils

  def initialize(window_width)
    @window_width = window_width
    super(0, 0)
  end

  def window_width
    @window_width
  end

  def col_max
    return 3
  end
 
  def make_command_list
    add_command("Transfer", :transfer)
    add_command("Empty Compact Inv", :empty)
    add_command("Done", :done, compact_weight <= compact_weight_limit)
  end
end

#==============================================================================
# ** Window_Weight
#------------------------------------------------------------------------------
#  This window displays the party's carry capacity.
#==============================================================================

class Window_Weight < Window_Base
  include WeightUtils
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, window_width, fitting_height(1))
    refresh
  end
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
    return 160
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    cw = compact_weight
    wl = compact_weight_limit
    draw_text(0, 0, contents.width, line_height, "Weight: #{cw}/#{wl}", 1)
  end
  #--------------------------------------------------------------------------
  # * Open Window
  #--------------------------------------------------------------------------
  def open
    refresh
    super
  end
end

class Window_CategoryInv < Window_ItemCategory
  def item_windows=(windows)
    @item_windows = windows
    update
  end

  def update
    super
    if @item_windows.is_a?(Array)
      @item_windows.each do |window|
        window.category = current_symbol if window.respond_to?(:category=)
        window.refresh if window.respond_to?(:refresh)
      end
    end
  end
end

#  Full Inventory Window
class Window_FullInventory < Window_ItemList

  def process_cursor_move
    return unless cursor_movable?
    last_index = @index
    cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
    cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
    #cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
    #cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
    cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
    cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
    Sound.play_cursor if @index != last_index
  end
 
  def col_max
    return 1
  end
end

#  Compact Inventory Window
class Window_CompactInventory < Window_ItemList

  def process_cursor_move
    return unless cursor_movable?
    last_index = @index
    cursor_down (Input.trigger?(:DOWN))  if Input.repeat?(:DOWN)
    cursor_up   (Input.trigger?(:UP))    if Input.repeat?(:UP)
    #cursor_right(Input.trigger?(:RIGHT)) if Input.repeat?(:RIGHT)
    #cursor_left (Input.trigger?(:LEFT))  if Input.repeat?(:LEFT)
    cursor_pagedown   if !handle?(:pagedown) && Input.trigger?(:R)
    cursor_pageup     if !handle?(:pageup)   && Input.trigger?(:L)
    Sound.play_cursor if @index != last_index
  end
 
  def include?(item)
    return false if item.nil?
    item.is_a?(RPG::Item) && $game_party.compact_item_number(item) > 0
  end

  def make_item_list
    @data = $game_party.compact_inventory.uniq.select { |item| include?(item) }
    @data.push(nil) if include?(nil) 
  end

  def col_max
    return 1
  end
end

# NOT USED NOW... For later when the compact inventory is in use
#  Footer Window for Weight Display
class Window_Weight_footer < Window_Base
  include WeightUtils

  def initialize
    super(0, Graphics.height - 64, Graphics.width, 64)
    refresh
  end

  def refresh
    contents.clear
    cw = current_weight
    wl = compact_weight_limit
    draw_text(0, 0, contents.width, line_height, "Weight: #{cw}/#{wl}", 1)
  end

  def weight_exceeded?
    current_weight > compact_weight_limit
  end
end

#  Scene for Inventory Transfer
class Scene_InventoryTransfer < Scene_MenuBase
  include WeightUtils

  def start
    super
    create_help_window
    create_weight_window
    create_action_window
    create_category_window
    create_inventory_windows
  
    activate_action_window
    deactivate_full_inventory
    deactivate_compact_inventory
  end

# * Window Creation
#--------------------------------------------------------------------------
  def create_weight_window
    @weight_window = Window_Weight.new
    @weight_window.viewport = @viewport
    @weight_window.x = Graphics.width - @weight_window.width
    @weight_window.y = @help_window.height
  end
 
  def create_action_window
    @action_window = Window_TransferActions.new(@weight_window.x)
    @action_window.viewport = @viewport
    @action_window.y = @help_window.height
    @action_window.set_handler(:transfer, method(:on_begin_transfer))
    @action_window.set_handler(:empty, method(:on_empty_compact))
    @action_window.set_handler(:done, method(:on_done))
  end

  def create_category_window
    @category_window = Window_CategoryInv.new
    @category_window.viewport = @viewport
    @category_window.y = @action_window.y + @action_window.height
    @category_window.deactivate
    @category_window.set_handler(:ok,     method(:on_category_ok))
    @category_window.set_handler(:cancel, method(:on_category_cancel))
  end

  def create_inventory_windows
    wy = @category_window.y + @category_window.height
    wh = Graphics.height - wy
  
    create_full_inventory_window(wy, wh)
    create_compact_inventory_window(wy, wh)

    @category_window.item_windows = [@full_inventory, @compact_inventory]
  end

  def create_full_inventory_window(wy, wh)
    @full_inventory = Window_FullInventory.new(0, wy, Graphics.width / 2, wh)
    @full_inventory.viewport = @viewport
    @full_inventory.help_window = @help_window
    #@full_inventory.status_window = @status_window
    @full_inventory.set_handler(:ok,     method(:on_transfer))
    @full_inventory.set_handler(:cancel, method(:on_inventory_cancel))
    @full_inventory.make_item_list
  
    @full_inventory_index = 0
  end
 
  def create_compact_inventory_window(wy, wh)
    @compact_inventory = Window_CompactInventory.new(Graphics.width / 2, wy, Graphics.width / 2, wh)
    @compact_inventory.viewport = @viewport
    @compact_inventory.help_window = @help_window
    #@compact_inventory.status_window = @status_window
    @compact_inventory.set_handler(:ok,  method(:on_transfer))
    @compact_inventory.set_handler(:cancel, method(:on_inventory_cancel))
    @compact_inventory.make_item_list

    @compact_inventory_index = 0
  end
 
  def update
    super
    handle_inventory_switch
    #refresh_all
  end

  def handle_inventory_switch
    if @full_inventory.active && Input.trigger?(:RIGHT)
      switch_to_compact_inventory
      Sound.play_cursor
    elsif @compact_inventory.active && Input.trigger?(:LEFT)
      switch_to_full_inventory
      Sound.play_cursor
    end
    @full_inventory.opacity = @full_inventory.active ? 255 : 160
    @compact_inventory.opacity = @compact_inventory.active ? 255 : 160 
  end
  
  def refresh_all
    @full_inventory.refresh
    @compact_inventory.refresh
  end

# * Action Window & called methods
#--------------------------------------------------------------------------
  def activate_action_window
    @action_window.activate
    @help_window.clear
  end
 
  def on_begin_transfer
    activate_category_window
  end

  def on_empty_compact
    #$game_party.compact_inventory.each do |item|
    #  $game_party.add_item(item, 1)
    #end
    #$game_party.compact_inventory.clear
    #refresh_all
  end

  def on_done
    #if compact_weight <= compact_weight_limit
      SceneManager.return
    #else
    #  Sound.play_buzzer
    #end
  end 
 
# * Category Window & called methods
#--------------------------------------------------------------------------
  def activate_category_window
    @category_window.activate
    @help_window.clear
  end
 
  def on_category_ok
    category = @category_window.current_symbol
    @full_inventory.category=category
    @full_inventory.refresh
    @full_inventory.index = 0
  
    @compact_inventory.category=category
    @compact_inventory.refresh
    @compact_inventory.index = 0
  
    activate_full_inventory
  end

  def on_category_cancel
    @category_window.deactivate
    activate_action_window
  end
  
# * Inventory Window & called methods
#--------------------------------------------------------------------------
  def switch_to_compact_inventory
    deactivate_full_inventory
    activate_compact_inventory
    @compact_inventory.index = @compact_inventory_index
  end
 
  def switch_to_full_inventory
    activate_full_inventory
    deactivate_compact_inventory
    @full_inventory.index = @full_inventory_index
  end

  def activate_full_inventory
    @active_inventory = @full_inventory
    @full_inventory.activate
    #@full_inventory.index ||= @full_inventory.select_last #@full_inventory_index
  end

  def deactivate_full_inventory
    @full_inventory.deactivate
  end
 
  def activate_compact_inventory
    @active_inventory = @compact_inventory 
    @compact_inventory.activate
    #@compact_inventory.index ||= @compact_inventory.select_last #@compact_inventory_index
  end
 
  def deactivate_compact_inventory
    @compact_inventory.deactivate
  end

  def deactivate_all_windows
    @action_window.deactivate if @action_window
    @category_window.deactivate if @category_window
    @full_inventory.deactivate if @full_inventory
    @compact_inventory.deactivate if @compact_inventory
  end
 
  def on_transfer
    item = @active_inventory.item
    transfer_item(item, 1)
    refresh_all
    @active_inventory.activate
  end

  def transfer_item(item, amount)
    if @active_inventory == @full_inventory
      $game_party.lose_item(item, amount)
      $game_party.add_to_compact(item, amount)
      Sound.play_ok
    elsif @active_inventory == @compact_inventory
      $game_party.remove_from_compact(item, amount)
      $game_party.gain_item(item, amount)
      Sound.play_ok
    end
  end

  def on_inventory_cancel
    deactivate_full_inventory
    @full_inventory.index = -1
    deactivate_compact_inventory
    @compact_inventory.index = -1
  
    activate_category_window
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/itemlist-skipping-index.179368/