Process Handling in menu

Hey all! I am currently working on a script (using Yanfly's Command Equip as a base) that mimics the in-battle equip change function in Final Fantasy games. Basically, while in the item menu in battle, pressing UP while on the topmost row of items will bring up another window where you can change your weapon and shield.

I have the actual equip change menu working, and I can access it from the item menu in-battle. My only problem right now lies in the Process Handling of :UP. I can't seem to make it only call up the in-battle equip scene when it is pressed while the cursor is on the top row of the menu only. I have it so that it triggers from either the top row, or while moving to the top row from the second row, but I'd like it to only work while the cursor is on the very top row of the menu. If this isn't possible, I can easily assign it to another button, but I'm going for authenticity here so it'd be nice if there was a way to make it work.

Here's what I have so far, this calls the scene when :UP is pressed from either the top row or second row. I only want the scene to be called when the cursor is already on the very top row.

return process_equip if @index <= 1 && Input.trigger?🙂UP)Like I said, this makes it work when :UP is pressed on the first row, but when :UP is pressed while the cursor is on the second row, it goes up to the first row AND calls the scene (below that, UP works fine and only scrolls through the item menu). I only want the scene called if the cursor is already on the top row, and :UP is pressed.

This is probably something really, really simple that I am just missing in my noobishness, but I've just started working with menus and windows so I have been learning by referencing the base scripts and others.

Thanks for any help! ^^
Indexes start at zero. Based on what you have already said, just use <= 0 instead of <= 1 and you should be fine.
Hmm, I tried <=0, and instead of calling the equip scene when pressing :UP from the first row, it is only the first item. However, it still moves the cursor up and also calls the scene when :UP is pressed from the first item on the second row. I was hoping that the scene would only be called if the cursor was on the first item before :UP was pressed. Is there some sort of way I can check the cursor's current position and only have the scene called if the cursor is already at index 0 before :UP is pressed? If that makes sense.

Thanks for the help!
Yes, then it depends entirely on where you are calling the code you posted above. Based on what you have said, it looks like it is being called between the time that the window updates and the next Input updates, so the trigger moves the window then in the same frame, the position is checked and equip is called. Ideally, it would be called before the window updates and consume the keypress if successful. To fix that, I need to see your entire code.
Ahh, that makes sense... yeah, I'm not sure how to go about fixing that on my own, so thank you for offering to have a look. Here's the script:

Spoiler
class Window_BattleEquip < Window_Selectable #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :status_window # Status window attr_reader :item_window # Item window #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(x, y, width) super(x, y, width, window_height) @actor = nil refresh end #-------------------------------------------------------------------------- # * Get Window Height #-------------------------------------------------------------------------- def window_height fitting_height(visible_line_number) end #-------------------------------------------------------------------------- # * Get Number of Lines to Show #-------------------------------------------------------------------------- def visible_line_number return 1 end def col_max return 2 end #-------------------------------------------------------------------------- # * Set Actor #-------------------------------------------------------------------------- def actor=(actor) return if @actor == actor @actor = actor refresh end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update super @item_window.slot_id = index if @item_window end #-------------------------------------------------------------------------- # * Get Number of Items #-------------------------------------------------------------------------- def item_max 2 #@actor ? @actor.equip_slots.size : 0 end #-------------------------------------------------------------------------- # * Get Item #-------------------------------------------------------------------------- def item @actor ? @actor.equips[index] : nil end #-------------------------------------------------------------------------- # * Draw Item #-------------------------------------------------------------------------- def draw_item(index) return unless @actor rect = item_rect_for_text(index) change_color(system_color, enable?(index)) contents.font.size = 14 draw_text(rect.x, rect.y, 92, line_height * 0.5, slot_name(index)) contents.font.size = 20 draw_item_name(@actor.equips[index], rect.x + 54, rect.y, enable?(index)) end #-------------------------------------------------------------------------- # * Get Equipment Slot Name #-------------------------------------------------------------------------- def slot_name(index) @actor ? Vocab::etype(@actor.equip_slots[index]) : "" end #-------------------------------------------------------------------------- # * Display Equipment Slot in Enabled State? #-------------------------------------------------------------------------- def enable?(index) @actor ? @actor.equip_change_ok?(index) : false end #-------------------------------------------------------------------------- # * Get Activation State of Selection Item #-------------------------------------------------------------------------- def current_item_enabled? enable?(index) end def item_window=(item_window) @item_window = item_window update end end class Scene_BattleEquip < Scene_MenuBase #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start super create_slot_window create_item_window end #-------------------------------------------------------------------------- # * Create Slot Window #-------------------------------------------------------------------------- def create_slot_window wx = 0 wy = 248 ww = Graphics.width wh = 200 @slot_window = Window_BattleEquip.new(wx, wy, ww) @slot_window.viewport = @viewport @slot_window.actor = @actor @slot_window.activate @slot_window.select(0) @slot_window.set_handler🙂ok, method🙂on_slot_ok)) @slot_window.set_handler🙂cancel, method🙂return_scene)) end #-------------------------------------------------------------------------- # * Create Item Window #-------------------------------------------------------------------------- def create_item_window wx = 0 wy = @slot_window.y + @slot_window.height ww = Graphics.width wh = 120 @item_window = Window_EquipItem.new(wx, wy, ww, wh) @item_window.viewport = @viewport @item_window.actor = @actor @item_window.set_handler🙂ok, method🙂on_item_ok)) @item_window.set_handler🙂cancel, method🙂on_item_cancel)) @slot_window.item_window = @item_window end #-------------------------------------------------------------------------- # * Slot [OK] #-------------------------------------------------------------------------- def on_slot_ok @item_window.activate @item_window.select(0) end #-------------------------------------------------------------------------- # * Slot [Cancel] #-------------------------------------------------------------------------- def on_slot_cancel @slot_window.unselect end #-------------------------------------------------------------------------- # * Item [OK] #-------------------------------------------------------------------------- def on_item_ok Sound.play_equip @actor.change_equip(@slot_window.index, @item_window.item) @slot_window.activate @slot_window.refresh @item_window.unselect @item_window.refresh end #-------------------------------------------------------------------------- # * Item [Cancel] #-------------------------------------------------------------------------- def on_item_cancel @slot_window.activate @item_window.unselect end def on_actor_change end endclass Scene_Battle alias scene_battle_create_item_window_ry create_item_window def create_item_window scene_battle_create_item_window_ry @item_window.set_handler🙂equip, method🙂command_equip)) end def command_equip Graphics.freeze @info_viewport.visible = false actor = $game_party.battle_members[@status_window.index] $game_party.menu_actor = actor previous_equips = actor.equips.clone @item_window.close.deactivate #--- SceneManager.call(Scene_BattleEquip) SceneManager.scene.main# SceneManager.force_recall(self) #--- @item_window.open.activate @info_viewport.visible = true @status_window.refresh perform_transition end endclass Window_BattleItem < Window_ItemList def process_handling return unless open? && active return process_ok if ok_enabled? && Input.trigger?🙂C) return process_equip if @index <= 0 && Input.trigger?🙂UP) return process_cancel if cancel_enabled? && Input.trigger?🙂 return process_pagedown if handle?🙂pagedown) && Input.trigger?🙂R) return process_pageup if handle?🙂pageup) && Input.trigger?🙂L) end def process_equip Sound.play_cursor Input.update deactivate call_handler🙂equip) end end
It's quite a mess since I haven't changed/edited the notation from the default scripts I edited. In my game, my item window is resized to the battlestatus size, so the equip window overlays it nicely. It seems to work fine in a fresh project minus the cursor issue, though. Thanks again for taking a look!
To solve your cursor problem, we just need to perform the check before the cursor moves, so:

class Window_BattleItem < Window_ItemList def update return process_equip if @index <= 1 and Input.trigger?🙂UP) # perform check to go to equip super # run superclass method for update, contains cursor movement and other processing checks end endYou should remove the check from process_handling if using this one.Here, we are just inserting the check before the other update methods for the window run. Since process_equip leads directly into a method where an entire scene is run, you shouldn't even need to cut the processing short here if the check succeeds (the return might not be necessary there) since the called scene has already terminated before the process_equip method is even completed. Scenes aren't really meant to be called like you have there by calling a scene and then doing the entire processing on the spot no matter where you are in the code, but if you aren't running into any other issues with that, I'd leave it be.
Thanks! That solves the problem in the item window, but now, if the cursor in the item window is at index 1 or 0, pressing :UP calls the equip scene no matter what window I'm in (actor command window, etc). If I go into the item window and move the cursor down, the behavior stops in other windows as well. I don't understand why that's happening because the change is only in the Window_BattleItem class, right? Is it somehow checking the item window index regardless of what the current window is? Would aliasing it somehow help? I removed the call from process handling as well. I tested it in a fesh project and the behavior is the same.

Sorry to be a pain, and thank you for the detailed explanations of what's going on, I'm trying to wrap my head around this stuff.
Ah, I forgot the very important check to see if the window is actually ready to receive input:

Code:
class Window_BattleItem < Window_ItemList  def update    return process_equip if @index <= 1 and Input.trigger?(:UP) and open? && active # perform check to go to equip    super # run superclass method for update, contains cursor movement and other processing checks  end  end
The 'ready to receive input' check happens automatically at the beginning of process_handling, but since we moved the check here we have to be explicit and add it. All windows update every frame, so 'update' is run whether or not the window can receive input, so we just have to explicit check if it can receive input before running process_equip here.
It works great now, thank you!

I had actually thought of trying to make it check if the window was open and active, but I was going about it wrong and trying to put the check into process_equip rather than before the update and it was causing all sorts of issues. ><

Thank you so much for all your help, and most of all for explaining how you made it work. I'm starting to understand how all of this stuff works now. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/process-handling-in-menu.23796/