Skip invalid options

Is there a way for the game's cursor to skip invalid options in the menu (including items and weapon scenes)?
Just like the options in gray(In the red box)
H~N5`Q4M%ODPVALYRFZAICY.png
I~C]~4]9Q0IU()16NFDU5`P.png
DKAZHZ87YXZVNIUP_OTDJR0.png
It's just a matter of telling it to keep looking for the next available index (position) there.
Sadly, it's already way past my bedtime. XD
It's just a matter of telling it to keep looking for the next available index (position) there.
Sadly, it's already way past my bedtime. XD
It seems like It need a script, but I am illiterate in this area
Ruby:
class Window_Selectable < Window_Base
  alias :tlb_skipdisabled_select :select
  def select(index)
    if (@list != nil && @list[index] != nil && !@list[index][:enabled]) || (@data != nil && !enabled?(@data[index]))
      if index == self.index
        Sound.play_cursor
      else
        if index < self.index
          select(index - 1)
        else
          select(index + 1)
        end
      end
    else
      tlb_skipdisabled_select(index)
    end
  end
end

This is the basic gist of how you'd do it. I haven't tested it with every window so it's possible there are cases where it won't quite work properly.
Ruby:
class Window_Selectable < Window_Base
  alias :tlb_skipdisabled_select :select
  def select(index)
    if (@list != nil && @list[index] != nil && !@list[index][:enabled]) || (@data != nil && !enabled?(@data[index]))
      if index == self.index
        Sound.play_cursor
      else
        if index < self.index
          select(index - 1)
        else
          select(index + 1)
        end
      end
    else
      tlb_skipdisabled_select(index)
    end
  end
end

This is the basic gist of how you'd do it. I haven't tested it with every window so it's possible there are cases where it won't quite work properly.
It doesn't seem to work properly...When I try to move the cursor by pressing the direction key, it will report an error
NOYW0_R71CN066J`Q%[F1)N.png
"I haven't tested it with every window so it's possible there are cases where it won't work properly."
WR(TFFP$)9}E@XF(9I0NY87.gif

"I haven't tested it with every window so it's possible there are cases where it won't work properly."

Original thread: https://forums.rpgmakerweb.com/threads/skip-invalid-options.160445/