Juan J. Sánchez
Sponsor
Ruby:
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if self.active and @item_max > 0 and @index >= 0
if Input.repeat?(Input::DOWN)
if Input.press?(Input::SHIFT)
$game_system.se_play($data_system.cursor_se)
n = @index + page_item_max
@index = n > @item_max - 1 ? @item_max - 1 : n
elsif (@column_max == 1 and Input.trigger?(Input::DOWN)) or
@index < @item_max - @column_max
$game_system.se_play($data_system.cursor_se)
unless @commands[(@index + @column_max) % @item_max] == nil
@index = (@index + @column_max) % @item_max
else
@index = (@index + 1 + @column_max) % @item_max until
@commands[(@index + @column_max) % @item_max] != nil
end
end
end
if Input.repeat?(Input::UP)
if Input.press?(Input::SHIFT)
$game_system.se_play($data_system.cursor_se)
n = @index - page_item_max
@index = n < 0 ? 0 : n
elsif (@column_max == 1 and Input.trigger?(Input::UP)) or
@index >= @column_max
$game_system.se_play($data_system.cursor_se)
unless @commands[(@index - @column_max + @item_max) % @item_max] == nil
@index = (@index - @column_max + @item_max) % @item_max
else
@index = (@index - 1 - @column_max + @item_max) % @item_max until
@commands[(@index - @column_max + @item_max) % @item_max] != nil
end
end
end
if Input.repeat?(Input::RIGHT)
if @column_max >= 2 and @index < @item_max - 1
$game_system.se_play($data_system.cursor_se)
@index += 1
end
end
if Input.repeat?(Input::LEFT)
if @column_max >= 2 and @index > 0
$game_system.se_play($data_system.cursor_se)
@index -= 1
end
end
if Input.repeat?(Input::R)
if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
$game_system.se_play($data_system.cursor_se)
@index = [@index + self.page_item_max, @item_max - 1].min
self.top_row += self.page_row_max
end
end
if Input.repeat?(Input::L)
if self.top_row > 0
$game_system.se_play($data_system.cursor_se)
@index = [@index - self.page_item_max, 0].max
self.top_row -= self.page_row_max
end
end
end
if self.active and @help_window != nil
update_help
end
update_cursor_rect
update_scroll
update_cursor
end
The algorithm is a simple up and down cursor movement algorithm for a command menu. It's supposed to skip commands that are set to nil, but it doesn't seem to work properly and I have no idea what's wrong. Can someone please take a look? If you need more information, please let me know.