Issues with Windows_Selectable

Any gotchas for the Window_Selectable, and making it change with arrow key presses?

I'm making a menu, and cannot get the highlighter moving up and down.  I can hard code setting @index to something, and the option will highlight.  I can also back out thanks to my own listener for that.

But I thought that Window_Selectable is supposed to support automatically scrolling/selecting with the arrow keys?  Isn't that the point of the object?

I get the feeling I'm missing something obvious here.  Are there any common gotcha's with this menu?  How is it supposed to behave?

My code is quite a mess, but all the content is displaying correctly in the window, so I am pretty sure that part is working just fine.*  

Looking over the default rpg maker code, I don't see any place where these windows and scenes listen for the arrow key inputs, they only put listeners for the back and forward buttons.  So I'm left thinking scrolling and arrow key moving the highlighter around is supposed to be automatic?  

(*The menu I am making is added onto the Yanfly menu system, and needs data from the Cannibalism script to function.  It's for a "hit list" of all eaten enemies per actor, so I'll have to start a thread to post it.)
I've moved this into its own thread, as I expect it to generate quite a bit of discussion


Yes, Window_Selectable is supposed to automatically scroll if you have more items than will fit in the window, and SHOULD move your cursor with just the arrow keys.


If it's not, the first thing I would questions is, is the window activated? That is usually the problem when I have a window that displays correctly but I'm getting no response from the keys. If you look at Window_Selectable's initialize method, the last thing it does is deactivate the window. Therefore, by default, it will never "do" anything. You have to activate it before it will start listening for keystrokes.


If that turns out not to be the problem, you will need to add the scripts here for both the window class you've made, and the scene class that uses it. Make sure you put them in code tags to preserve formatting, and as they're probably going to be quite lengthy, wrap spoiler tags around them too 🙂
Just to make sure I'm doing this right, you would activate the window by doing something like this right?
 

def initialize(x, y, width, height) super activate #<-- this should set the window active.endIf so, I've done that and still can't move it at all.  

I'll have to clean up my comments a bit before posting, I tend to think in comments when coding and made quite the mess of comments, not all of which are even accurate anymore.  When I get this cleaned up, I'll post my window and scene code.
You'd normally do something like this in your scene class:

Code:
@mywindow = Window_Selectable.new(x, y, width, height)# set other stuff like viewport, help window, etc if [email hidden]
You may also have to deactivate the previous window, if there was one, depending on what type of window it was.
Ok, I poked around some more, and I'm going to have to post this up.  Everything seems to be checking out, the window is active, the content shows up, but the menu simply won't move or do anything besides let me back out.  It closes fine, and seems to be reopening and displaying all the data correctly per actor.  It just won't let the player move the cursor for some reason.

To run this, you'll need to have both:

-the cannibalism script, so actors can have the array of what they ate.  The database needs to have cannibal tags on every enemy, as I don't have a safety for now if some don't have scripts.  The script does check for empty names "" and skips them, so you should be ok if you just delete most of them and tag the last few.

-the Yanfly Menu Ace script, as I haven't touched the vanilla compatible mode of this script since first draft, and it's probably buggy without using the new code in the Yanfly part.

You'll also need to add the scene to the Yanfly menus yourself, I've included some rough copy paste install lines in the comments down near the yanfly compatible part.(they are just a straight copy of what I added, so they should work assuming you install them to the right place in the yanfly menu script.)

Thanks in advance for your time.  I know it's a pretty long script.  It's one of my first scene window scripts, so it's probably not as efficient or short as it could be, but I'm learning as I go.

Spoiler
Code:
#-------------------------------------------------------------------#  Cannibal hit list#-------------------------------------------------------------------#   by Dark Griffin#   version 0.1#-------------------------------------------------------------------# Add on to the cannibalism script by Kread-EX, won't work without it.## version 0.1#   Provides a menu to check what enemies a party member has eaten.#   The menu simply checks if they have any cannibal count for now,#   I haven't worked out how to get the enemy eating_limit outside#   of combat yet(the flags don't exist on the enemy objects till the #   troop is loaded into#   combat memory in the default cannibalism script, so I'll need to#   write my own parser to emulate that part of the engine).#   Not quite up to writing a notespace parcer yet.#   This should be fine for my game, as each enemy only gives stats#   once anyway.#-------------------------------------------------------------------if !$imported["YEA-AceMenuEngine"]#-------------------------------------------------------------------# Non Yanfly menu addon code#  NOTE: This is currently untested and probably broken, but won't run unless#  in vanilla RPG Maker.#-------------------------------------------------------------------class Scene_Menu < Scene_MenuBase  def create_command_window    @command_window.set_handler(:hitlist,      method(:Scene_CHitList))  end    def Scene_CHitList    SceneManager.call(Scene_Cannibal_Hitlist)  endend#-------------------------------------------------------------------end#   End of non yanfly menu add on code.#-------------------------------------------------------------------#-------------------------------------------------------------------#  Window_Cannibal_Hitlist#-------------------------------------------------------------------class Window_Cannibal_Hitlist < Window_Selectable    #-------------------------------------------------------------------    #  Public instance variables    #-------------------------------------------------------------------    attr_accessor :hitlist    attr_accessor :monsterlistnames    attr_accessor :partymemberID    #-------------------------------------------------------------------    #  initialize    #-------------------------------------------------------------------    def initialize(x, y, width, height)      super      @index = 0 # just a quick overwrite to allow selections.      @column_max = 1 #single column display, we just want a list.      @cursor_fix = false #no idea what this does, but most menus have it off.      @cursor_all = false #no idea what this does, but most menus have it off.      @hitlist = [] #set hitlist to array type, and empty.      @partymemberID = $game_party.menu_actor.id #get the selected party member      calculate_hitlist # calculate the hitlist arrays, so we have data                        # to work with      refresh  # refresh the window to make it show up      enable_indexing_if_content #check if there is any content to display    end        #-------------------------------------------------------------------    #  Test to see if process_cursor_move happens    #  Yes, it runs every frame the menu is open when this is enabled.    #-------------------------------------------------------------------    #def process_cursor_move        #super        #p("process_cursor_move has run")    #end        #-------------------------------------------------------------------    #  enable_indexing_if_content  - turns index to 0 and populates list    #  when there is content in the @monsterlistnames array.    #-------------------------------------------------------------------    def enable_indexing_if_content      if @monsterlistnames != []        #set index to enable cursor        @index = 0        #set item_max to length of hitlist        @item_max = @monsterlistnames.length      end    end    #-------------------------------------------------------------------    # calculate_hitlist  -  build the @monsterlistnames array    #     also builds the @hitlist array from the party member's data    #-------------------------------------------------------------------    def calculate_hitlist      #if there are eaten enemies in the list, start parsing      if !$game_actors[@partymemberID].devoured.nil?        #clear ids and names arrays        monster_ids = []        @monsterlistnames = []        #for every entry in the monster db, check it.        $data_enemies.each_index do |i|          if $data_enemies[i] != nil  # if not nil            if $data_enemies[i].name != nil # if it has a name.              monster_ids.push $data_enemies[i].id  # push the id to array            end          end        end        #for every id found, do this.        monster_ids.each_index do |i|          if $data_enemies[i] != nil #if not nil            @monsterlistnames.push $data_enemies[i].name #add the name to array          end        end        #get actor hit list        actor_hit_list = $game_actors[@partymemberID].devoured        # run over all of actor hit list, and push monster name        #   entries to @hitlist if        #   they have eaten the enemy.        actor_hit_list.each_index do |i|          #check against database          if actor_hit_list[i] != nil            #if the monster has been eaten, push name to hitlist.            @hitlist.push $data_enemies[i].name          end        end      else  #if there are no enemies eaten, just set to nothing.        @hitlist = []      end    end    #-------------------------------------------------------------------    #  refresh data - clears contents , then calls can_draw_all_monster_names    #-------------------------------------------------------------------    def refresh      #p("clearing contents")      contents.clear      #p("drawing all items in menu")      can_draw_all_monster_names    end    #-------------------------------------------------------------------    #  can draw all monster names - loop through monster name list and    #   call can_draw_monster_name for each index.    #-------------------------------------------------------------------    def can_draw_all_monster_names      #declare offset value      @monster_offset = 0      @monsterlistnames.each_index do |i|        #only draw if not nil and has name.        if i != nil && @monsterlistnames[i] != ""          can_draw_monster_name(i) # draw monster in list        end        # if the name was "" then back up one menu item for any remaining        #  monsters in the list.  This avoids gaps used in the editor to        #  sort monsters into groups when the editor data has them.        if @monsterlistnames[i] == ""          @monster_offset = @monster_offset - 1        end      end    end    #-------------------------------------------------------------------    #  can draw monster name - checks if item index is in hitlist,     #     modifies it depending on result, and draws the item to contents    #-------------------------------------------------------------------    def can_draw_monster_name(index)      item = @monsterlistnames[index]      # check if item even has name      if item != ""        #-----------------        # check if item is in both arrays        if @hitlist.include?(item)          # if it is, add a "* " to the string          item = "* " + item        else          # if not, add a "- " instead          item = "- " + item        end        #-----------------        #draw the line of text for the enemy item entry.        ypos = line_height * (index + @monster_offset)        contents.draw_text(x + 24, ypos, width, line_height, item)      end    end    #-------------------------------------------------------------------end#####################################################################################################  Scene_Cannibal_Hitlist#############################class Scene_Cannibal_Hitlist < Scene_MenuBase  #-------------------------------------------------------------------  #  attribute accessors for the scene object  #-------------------------------------------------------------------  attr_accessor :WindowC  #-------------------------------------------------------------------  #  Start  #-------------------------------------------------------------------  def start    super    @WindowC = Window_Cannibal_Hitlist.new(0,0,Graphics.width,Graphics.height)    set_handlers_on_window    @WindowC.activate    p("is window active?")    p(@WindowC.active)  end  #-------------------------------------------------------------------  #  set handlers on window - sets the cancel button for now  #-------------------------------------------------------------------  def set_handlers_on_window    @WindowC.set_handler(:cancel, method(:return_scene))  end  #--------------------------------------------------------------------------  # Dispose Window  #--------------------------------------------------------------------------  def terminate    @WindowC.dispose  end    end######################################################################-------------------------------------------------------------------#   Start of Yanfly addon code#-------------------------------------------------------------------if $imported["YEA-AceMenuEngine"]############################################################################  NOTE: To add to the menu, use this tag in custom commands#  :chitlist => ["Prey List",          0,              0, :Scene_CHitList],#-------------------------------------------------------------------# You will also need to add this to the commands menu list for it to appear#  :chitlist,      # Opens the cannibalism hit list menu.###########################################################################  #-------------------------------------------------------------------  #   Add to Yanfly menu  #-------------------------------------------------------------------  class Scene_Menu < Scene_MenuBase    #-------------------------------------------------------------------    #  Scene_CHitList definition - selects a member, then launches the window    #-------------------------------------------------------------------    def Scene_CHitList      #pick a party member      @status_window.select_last      @status_window.activate      @status_window.set_handler(:ok,     method(:openCannibalHitlist))      @status_window.set_handler(:cancel, method(:on_personal_cancel))    end    #-------------------------------------------------------------------    #  open cannibal hit list - calls a change to the cannibal hitlist scene    #-------------------------------------------------------------------    def openCannibalHitlist      #p("status window passed an ok command")      @status_window.deactivate      SceneManager.call(Scene_Cannibal_Hitlist)    end  end#########################################################end #end Yanfly menu add on

Original thread: https://forums.rpgmakerweb.com/threads/issues-with-windows_selectable.21342/