Help with my Script (In-game State Glossary)[XP]

I'm trying to make an in-game State Glossary. The end goal is to have it look like the Item Window but instead of showing actor info at the top, it just says "State Glossary" and the selectable stuff is a list of the states in alphabetical order regardless of their IDs. When you select them, another window pops up that shows a description of that state (I can easily do this part).

What I managed thus far
I seem to be successful in copying the Window_Item code and using that for the states but having issues with Scene_Item. I copied it, removed the target_window (don't need it), but the cursor stays still. It doesn't blink or move, and I'm still pretty new to scriping so I have no idea what caused it, and I really don't know how the cursor really works in anything. I normally just fumble, place random hashtags and it eventually fixes itself but that tactic isn't working here.

So what I need
1. To get the cursor working
2. Get the states in Alphabetical order.
Note: I assume to do #2, I would go to line 79, and add the actual names to the arrays instead of the IDs by doing something like @data.push($data_states.name.to_s) and then go to line 102 and change state.name to just state, THEN... sort? Help section talks a lot of code mumbo jumbo, but I assume it sorts 0 - 9, then sorts A - Z, right? Go to line 95 and put state = @Data[index].sort <= Like this?

I broke the script twice having to start over so to save my sanity, I decided to just ask for help lol. Here is the script. I haven't gotten to making the second window.
Spoiler: The Script
Ruby:
#==============================================================================
# Window_StateDescription
#==============================================================================

class Window_StateDescription < Window_Base
 
 
  def initialize

    super(0, 64, 640, 416)
    
    self.contents = Bitmap.new(width - 32, height - 32)

    self.contents.font.name = "Arial"

    self.contents.font.size = 16
    refresh
  end

  def refresh
    self.contents.clear
    # Same as above.
    @x = 4
    @y = 32
    @Y = -10
    
  end
    
    
  def update
    super
    return unless self.active
  end
    
    

end

#==============================================================================
#Window_States
#==============================================================================

class Window_States < Window_Selectable
 
  def initialize
    super(0, 64, 640, 416)
    @column_max = 2
    refresh
    self.index = 0
    if $fontface != nil
      self.contents.font.name = $fontface
      self.contents.font.size = 16
    elsif $defaultfonttype != nil
      self.contents.font.name = $defaultfonttype
      self.contents.font.size = 16
    end
    self.contents.font.bold = true
    self.active, self.index = false, 0
    refresh
  end
 
  #--------------------------------------------------------------------------
  # * Get State
  #--------------------------------------------------------------------------
  def state
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []

    for i in 1...$data_states.size
      @data.push($data_states[i])
    end

    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    state = @data[index]
    self.contents.font.color = normal_color
    x = 4 + index % 2 * (288 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))

    self.contents.draw_text(x + 28, y, 212, 32, state.name, 0)

  end
 
end


#==============================================================================
# Scene_State
#==============================================================================

class Scene_State
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    # Make help window, item window
    #@help_window = Window_Help.new
    @item_window = Window_States.new
    # Associate help window
    #@item_window.help_window = @help_window
    # Make target window (set to invisible / inactive)
    #@target_window = Window_Target.new
    #@target_window.visible = false
    #@target_window.active = false
    # Execute transition
    Graphics.transition
    # Main loop
    loop do
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Frame update
      update
      # Abort loop if screen is changed
      if $scene != self
        break
      end
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose of windows
    #@help_window.dispose
    @item_window.dispose
    #@target_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Update windows
    #@help_window.update
    @item_window.update
    #@target_window.update
    # If item window is active: call update_item
    if @item_window.active
      update_item
      return
    end
    # If target window is active: call update_target
    #if @target_window.active
    #  update_target
    #  return
    #end
  end
  #--------------------------------------------------------------------------
  # * Frame Update (when item window is active)
  #--------------------------------------------------------------------------
  def update_item
    # If B button was pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new(0)
      return
    end
    # If C button was pressed
    if Input.trigger?(Input::C)
      # Get currently selected data on the item window
      #@item = @item_window.item
      # Play decision SE
      $game_system.se_play($data_system.decision_se)
      # If effect scope is an ally
      # If effect scope is other than an ally
      return
    end
  end

 
 
 
end
Once you've gotten rid of $data_states[0] because it's equal to nil, you've got two options to keep them sorted.

1. Sort $data_states
2. Define 2 arrays, one holding the names and another one holding the ID's or any other details you might need instead.

Obviously, option 1 is the easiest. This one would allow you to easily find all the data corresponding to a given state at once.

Ruby:
@data = $data_states[1..-1].sort

That line will sort them out... by ID.

Ruby:
@data = $data_states[1..-1].sort{|a, b| a.name <=> b.name }

This new line should work fine..
Once you've gotten rid of $data_states[0] because it's equal to nil, you've got two options to keep them sorted.

1. Sort $data_states
2. Define 2 arrays, one holding the names and another one holding the ID's or any other details you might need instead.

Obviously, option 1 is the easiest. This one would allow you to easily find all the data corresponding to a given state at once.

Ruby:
@data = $data_states[1..-1].sort

That line will sort them out... by ID.

Ruby:
@data = $data_states[1..-1].sort{|a, b| a.name <=> b.name }

This new line should work fine..
This works. Never thought of setting a range of 1 to -1. I assume the program assumes you mean all the states if they are given a -1? Good to know. I don't get $data_states[0] because I told the script to always start at 1.

Any ideas on how to fix the cursor?

EDIT: Fixed it. Changed my initialization to be carbon copy of the one in Window_item, and I just realized self.active was equal to false which is why the cursor was stuck lol.
One of the conditions that prevent the cursor box from updating is self.active being equal to true or simply self.active, meaning that all objects evaluate to true if they're not a NilClass or FalseClass object. The only exception to this logical rule is the eval method call in Interpreter class. If you send a false value back, it can freeze the game in no time. So you either get the patch for command_355 IIRC or send back a true or nil value instead.

-1 just means last index of the array and you can decrease it as long as there's still a value contained in that array. Otherwise, you'd get an Out of Range error or the like.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-my-script-in-game-state-glossary-xp.153235/