RGSS1 (XP) Script issue

● ARCHIVED · READ-ONLY
Started by AceTheMad 3 posts View original ↗
  1. So, then.

    I was FINALLY dipping my fingers into the RGSS scripting world. Decided to start with a simple XP game. I'm working on a simple monster book.

    I've...already ran into an issue.

    I was working on a list of monsters to select from. At first, it looks fine. But then I scroll down.

    I get this:

    Test 10_7_2018 4_50_40 PM.png

    Basically, it's making the size of the list the exact amount of enemies I have in the game.

    But, the text is only displaying the initial amount of enemies visible in the window.

    Here's what I've got so far:

    Code:
    #==============================================================================
    #
    # My first RGSS Script. Hopefully, this works out well
    #
    # This is a standard bestiary script. It displays a list of enemies that
    # you've encountered and their image and stats.
    #
    # Author: AceTheMad
    #==============================================================================
    
    class Window_Monster_Image < Window_Base
      #-----------------------------------------------------------------------------
      # * Object Initialization
      #-----------------------------------------------------------------------------
      def initialize
        super(220, 0, 420, 240)
        self.contents = Bitmap.new(width - 32, height - 32)
        refresh
      end
     
      def refresh
        self.contents.clear
        self.contents.font.color = normal_color
        self.contents.font.size = MBook::TEXT_SIZE
        self.contents.draw_text(30, 30, contents.text_size(MBook::TEXT).width, MBook::TEXT_SIZE + 12, MBook::TEXT)
      end
    end
    
    class Monster_List < Window_Selectable
      def initialize
        super(0, 0, 220, 480)
        self.contents = Bitmap.new(width - 32, height - 32)
        @item_max = $data_enemies.compact.length
        @column_max = 1
        refresh
        self.index = 0
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        self.contents.clear
        for i in 0...@item_max
          draw_item(i)
        end
      end
      #--------------------------------------------------------------------------
      # * Draw Item
      #     index : item number
      #--------------------------------------------------------------------------
      def draw_item(index)
        y = 4 + index * 32
        self.contents.draw_text(0, y, 220, 32, $data_enemies.compact[index].name)
      end
    end

    And this, if you need it, is my scene code.

    Code:
    #-------------------------------------------------------------------------------
    # MonsterBook scene
    #-------------------------------------------------------------------------------
    class Monster_Book
      #-----------------------------------------------------------------------------
      # * Main Processing
      #-----------------------------------------------------------------------------
      def main
        @image_window = Window_Monster_Image.new
        @list_window = Monster_List.new
        Graphics.transition
        
        loop do
          Graphics.update
          
          Input.update
          
          update
          
          if $scene != self
            break
          end
        end
        
        Graphics.freeze
        
        @image_window.dispose
        @list_window.dispose
      end
     
      def update
        @image_window.update
        @list_window.update
      end
     
    end

    Forgive the lack of organization. I'm still new to this and care more about learning the language. X'D
  2. If this is your first venture into RGSS / Ruby Scripting... Bravo! But you really would wish to use the 'refresh' method to refresh all your data and not have it gathered in your initialize method. Initialize is used for housekeeping and reset. I tend to follow the basic methodology of other scripts, and rewrote your Monster_List class following typical standards of other classes like Window_Item.

    Code:
    #==============================================================================
    # ** Monster_List
    #------------------------------------------------------------------------------
    #  This window displays the list of monsters in your database
    #==============================================================================
    
    class Monster_List < Window_Selectable
      #--------------------------------------------------------------------------
      # * Object Initialization
      #--------------------------------------------------------------------------
      def initialize
        super(0, 0, 220, 480)
        @column_max = 1
        refresh
        self.index = 0
      end
      #--------------------------------------------------------------------------
      # * Refresh
      #--------------------------------------------------------------------------
      def refresh
        # Clear the window contents.
        if self.contents != nil
          self.contents.dispose
          self.contents = nil
        end
        # First, make or clear the @data array that stores your monsters
        @data = []
        # Add all the items in your enemies database
        for i in 1...$data_enemies.size
            @data.push($data_enemies[i])
        end
        # If monster count is not 0, make a bit map and draw all items
        @item_max = @data.size
        if @item_max > 0
          self.contents = Bitmap.new(width - 32, row_max * 32)
          for i in 0...@item_max
            draw_item(i)
          end
        end
      end 
      #--------------------------------------------------------------------------
      # * Draw Item
      #     index : item number
      #--------------------------------------------------------------------------
      def draw_item(index)
        item = @data[index]
        y = 4 + index * 32
        self.contents.draw_text(0, y, 220, 32, item.name)
      end
    end

    The comments I added are a bit ... different.. than the normal ones you'd see.

    Based on your code, I'm assuming that all your monsters are all available in the book at game start. It would be in the code....
    Code:
        # Add all the items in your enemies database
        for i in 1...$data_enemies.size
            @data.push($data_enemies[i])
        end
    ... where you add the enemies, so it is also here where you would decide if an enemy is even in the list (like if you do or don't show the ghost as yet). But if you got this far already... Nice.
  3. So DerVVulfman's answer is spot on, but I wanted to highlight the specific issue you were having. Basically, your "bitmap" wasn't tall enough. In your code, you wrote "self.contents = Bitmap.new(width - 32, height - 32)". This creates a fixed size bitmap that is the size of the *displayed* area. So when you scroll down, there's nothing to display even though you tried to draw things there. Think of it like this, you created a piece of paper the size of the displayed area. Then started writing down the names from top to bottom. When you got to the bottom, you kept on writing names but they weren't written on the piece of paper anymore, so the game doesn't show them.

    By contrast, in DerVVulfman's code, he wrote "self.contents = Bitmap.new(width - 32, row_max * 32)" where "row_max" was calculated earlier to be the number of rows needed to draw all the monsters. This dynamically creates a bitmap (or piece of paper) large enough to hold all the names.