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.

Question about arrays, window_base or window_help

Is it possible to display an array if the window inherits Window_Base or Window_Help methods/characteristics? I tried to do that already but any of them would just show the first value included in the array...
 
What am I doing?
I'm just trying to be able to see some sort of towns index on screen, but it only displays the first town name. I entered several town names but it did not show anything.
Window_Towns was created and it inherits the methods included in Window_Base.
 
He, he, he. I'm sorry, Seph. Now it is about to be released as a simple Allegiance Pack. I'm wondering if I could be able to include several "national" flags that would represent several kingdoms or republics. These flags, kingdoms or republics should be a complement of the Allegiance Pack but shouldn't change a single line in the code unless the code can be reduced without affecting the way it should work.
 
I would do something like that:
Code:
x=<some value>
y=<some value>
for city in cities
  bitmap = RPG::Cache.icon(flag_names[city.kingdom])
  self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
  self.contents.draw_text(x + 28, y, <space available>, 32, city.name, 0)
  y+=32
end

supposing that cities is an array of cities, a City is a class with a name and a kingdom, flag_names is an array indicating the names of the pics used for each kingdom (indices may be integers or names as well).
 
Well, this is what I was talking about.
Code:
#==============================================================================
# ** Window_Flags < Window_Base
#    version 0.2 BETA
#    by shadowball
#------------------------------------------------------------------------------
#  This class shows the user flags according to the lists of town's allegiences.
#==============================================================================
class Window_Flags < Window_Base
  FLAG =
  {
    # Allegiance        =>  National Flags
    Allegiance::Ally    => 'flaggecko',
    Allegiance::Neutral => 'flaggecko',
    Allegiance::Enemy   => 'flaggecko',
    Allegiance::Unknown => 'flaggecko'
  }
  
  COUNTRY =
  {
    # Empires, Kingdoms, Republics, Tyrannies, Unknown
    Allegiance::Ally    => 'New Geckoshire',
    Allegiance::Neutral => 'Republic of Mystic Valley',
    Allegiance::Enemy   => 'Tyranny of Gelbenfels',
    Allegiance::Unknown => '?????'
  }
  def initialize(x, y, allegiance)
    # Gather the towns of the same allegiance.
    @towns = $game_towns.get_towns(allegiance)
    # Create the window.
    @allegiance = allegiance
    x = 512
    y = 0
    super(x, y, 224, 192)
    opacity = 255
    self.contents = Bitmap.new(width - 32, height - 32)
    bitmap = RPG::Cache.picture(FLAG[@allegiance])
    px = 512
    py = 0
    self.contents.blt(px, py + 4, bitmap, Rect.new(0, 0, 192, 128), opacity)
    self.opacity = 128
    refresh
  end
  
  def refresh
    self.contents.clear
    x = 0
    y = 128
    nation = COUNTRY[@allegiance]
    self.contents.draw_text(x, y, 224, 32, nation, 0)
  end
end

Whenever I call this window, it'll just show the window and the text line, but no picture is displayed at all.
What did I wrong here?
 
You clear the contents you defined for the map and then draws text without blitting the image. If you want to make your image keep showing and still use the text, i reccomend you this:
Code:
  def initialize(x, y, allegiance)
    # Gather the towns of the same allegiance.
    @towns = $game_towns.get_towns(allegiance)
    # Create the window.
    @allegiance = allegiance
    x = 512
    y = 0
    super(x, y, 224, 192)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 128
    refresh
  end

 def refresh
    self.contents.clear
    x = 0
    y = 128
    bitmap = RPG::Cache.picture(FLAG[@allegiance])
    px = 512
    py = 0
    self.contents.blt(px, py + 4, bitmap, Rect.new(0, 0, 192, 128), opacity)
    nation = COUNTRY[@allegiance]
    self.contents.draw_text(x, y, 224, 32, nation, 0)
  end

I hope this works.
 

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