Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

It's a Messy code?

Well, I was wondering if the advanced scripters can help me with this messy code, I Think is too big, and too dirty... (I haven't put comments yet), what do you think?, a tip, an advice?.. something?.

The code

Code:
class Scene_Fish_Equipment < SDK::Scene_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #     actor_index : actor index

  #--------------------------------------------------------------------------

  def initialize

    super()

  end

  #--------------------------------------------------------------------------

  # * Main Sprite_Set

  #--------------------------------------------------------------------------

  def main_spriteset

    # Sets Up Spriteset

    @spriteset = Spriteset_Map.new

  end

  #--------------------------------------------------------------------------

  # * Main Processing : Window Initialization

  #--------------------------------------------------------------------------

  def main_window

    super

    @fishing_items             = Window_Fishing_Items.new

    @fishing_equipment         = Window_Fishing_Equipment.new

    @help_window               = Window_Help.new

    @help_window.back_opacity  = 160

    @help_window.set_text('Equipa tu Caña de Pescar y pon una Carnada', 1)

    @item_help                 = Window_Help.new

    @item_help.x               = @fishing_equipment.x

    @item_help.y               = @fishing_equipment.y - 64

    @item_help.width           = 256

    @item_help.contents        = Bitmap.new(@item_help.width - 32, 32)

    @item_help.back_opacity    = 160

    @fishing_items.help_window = @item_help

  end

  #--------------------------------------------------------------------------

  # * Frame Update

  #--------------------------------------------------------------------------

  def update

    super

    # 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_Map.new

      return

    end

    # If C button was pressed

    if Input.trigger?(Input::C)

      # Get currently selected data on the item window

      @item = @fishing_items.item

      # If Item at Cursor Position is nil

      if @item.nil?

        # Play Buzzer SE

        $game_system.se_play($data_system.buzzer_se)

        return

      end

      if @item.element_set.include?(Fishing::Equipment_Elements['Rods'][0])

        unless $game_party.fishing_level >= Fishing::Rod_Required_Level[@item.id]

          $game_system.se_play($data_system.buzzer_se)

          return

        end

        $game_system.se_play($data_system.equip_se)

        $game_party.equipped_rod = @item.id

        unless $game_party.equipped_rod_bait == 0

          $game_party.gain_item($game_party.equipped_rod_bait, 1)

          $game_party.equipped_rod_bait = 0

        end

        @fishing_items.refresh

        @fishing_equipment.refresh

        return

      end

      if @item.element_set.include?(Fishing::Equipment_Elements['Baits'][0])

        unless $game_party.equipped_rod != 0

          $game_system.se_play($data_system.buzzer_se)

          return

        end

        unless Fishing::Rod_Baits[$game_party.equipped_rod].include?(@item.id)

            $game_system.se_play($data_system.buzzer_se)

          return

        end

        # Play Equip SE

        $game_system.se_play($data_system.equip_se)

        unless $game_party.equipped_rod_bait == 0

          $game_party.gain_item($game_party.equipped_rod_bait, 1)

        end

        $game_party.equipped_rod_bait = @item.id

        $game_party.lose_item(@item.id, 1)

        @fishing_items.refresh

        @fishing_equipment.refresh

        return

      end

      return

    end

    # If X button was pressed

    if Input.trigger?(Input::X)

      if $game_party.equipped_rod == 0

        # Play Buzzer SE

        $game_system.se_play($data_system.buzzer_se)

      else

        # Play Equip SE

        $game_system.se_play($data_system.equip_se)

        $game_party.equipped_rod = 0

        if $game_party.equipped_rod_bait != 0

          $game_party.gain_item($game_party.equipped_rod_bait, 1)

          $game_party.equipped_rod_bait = 0

          @fishing_items.refresh

        end

        @fishing_equipment.refresh

      end

      return

    end

    # If Y button was pressed

    if Input.trigger?(Input::Y)

      if $game_party.equipped_rod_bait == 0

        $game_system.se_play($data_system.buzzer_se)

      else

        $game_system.se_play($data_system.equip_se)

        $game_party.gain_item($game_party.equipped_rod_bait, 1)

        $game_party.equipped_rod_bait = 0

        @fishing_items.refresh

        @fishing_equipment.refresh

      end

      return

    end

  end

end

Thanks for your time.
 
Code:
  #--------------------------------------------------------------------------

  # * Object Initialization

  #     actor_index : actor index

  #--------------------------------------------------------------------------

  def initialize

    super()

  end

If all you are doing here is calling the original initialize method, then this chunk may be omitted.

Code:
    @fishing_items             = Window_Fishing_Items.new

    @fishing_equipment         = Window_Fishing_Equipment.new

    @help_window               = Window_Help.new

    @help_window.back_opacity  = 160

    @help_window.set_text('Equipa tu Caña de Pescar y pon una Carnada', 1)

    @item_help                 = Window_Help.new

    @item_help.x               = @fishing_equipment.x

    @item_help.y               = @fishing_equipment.y - 64

    @item_help.width           = 256

    @item_help.contents        = Bitmap.new(@item_help.width - 32, 32)

    @item_help.back_opacity    = 160

    @fishing_items.help_window = @item_help

Good format on indenting the = marks to be lined up. Me likes. :thumb: However, @fishing_items instance doesn't exist. Probably just a naming error. ;)

The only thing I can suggest is making methods in Game_Party to handle all your equipping an unequipping of rods and baits. You have double code in your Input::C and X/Y equipping or unequipping items. It would be a little easier to just call

$game_party.equip_rod(item_id)

in these code blocks. It would also allow this more simply in call scripts as well (in the event you need them).



Other than that, good work. :thumb:
 
All there is to add is probably that you should stick to the default naming conventions and make windows have a _window in the end every time. Like Seph already said, @fishing_items is heavily misleading, and having something named @item_help won't help you in bigger scripts either...
So yeah:

@fishing_items -> @fish_item_window
@fishing_equipment -> @fish_equip_window
@help_window -> @caption_window (as this only seems to display a line of text all the time, at least within this class)
@item_help -> @help_window


Also, for your initialize comment header (that you don't need like Seph already said~), you have a actor_index explanation in there ^^ Copypaste is fine, but note what you copypaste...

Other than that, nice coding... Personally, I think the method headers you use the same way as the default are pretty useless, but they're perfectly fine to use. So yeah, good work here.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top