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.

Showing states as icons

I'm working on a CMS which is supposed to show the actor states as icons. I've managed to get this working fine in Window_Status:

Code:
    # Draw condition icons

    if @actor.states.include?(1)

      bitmap = RPG::Cache.icon("icon_symbol_death")

      self.contents.blt(0, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_death_g")

      self.contents.blt(0, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(2)

      bitmap = RPG::Cache.icon("icon_symbol_blood")

      self.contents.blt(24, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_blood_g")

      self.contents.blt(24, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(3)

      bitmap = RPG::Cache.icon("icon_symbol_fire")

      self.contents.blt(48, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_fire_g")

      self.contents.blt(48, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(4)

      bitmap = RPG::Cache.icon("icon_symbol_hunger")

      self.contents.blt(72, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_hunger_g")

      self.contents.blt(72, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(5)

      bitmap = RPG::Cache.icon("icon_symbol_toxic")

      self.contents.blt(96, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_toxic_g")

      self.contents.blt(96, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(6)

      bitmap = RPG::Cache.icon("icon_symbol_bio")

      self.contents.blt(120, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_bio_g")

      self.contents.blt(120, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(7)

      bitmap = RPG::Cache.icon("icon_symbol_rad")

      self.contents.blt(144, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_rad_g")

      self.contents.blt(144, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

    if @actor.states.include?(8)

      bitmap = RPG::Cache.icon("icon_symbol_psi")

      self.contents.blt(168, 400, bitmap, Rect.new(0, 0, 24, 24), 200)

    else

      bitmap = RPG::Cache.icon("icon_symbol_psi_g")

      self.contents.blt(168, 400, bitmap, Rect.new(0, 0, 24, 24), 60)

    end

 

The problem is that this code doesn't work in Window_MenuStatus or Window_Target. NoMethodError occurs instead ("undefined method 'states' for NilClass").

Can anyone help? Thanks in advance!
 

khmp

Sponsor

There isn't an instance variable called @actor in either of those classes. That's what that nil error is about. Both of them iterate through the entire party and draw all of them at once inside their respective refresh methods. If I could make a code design suggestion? You could add a method to Window_Base called draw_actor_states and put all of that stuff in it. Make sure to pass into the method, an actor, x coordinate, and a y coordinate. Something like below:

Code:
class Window_Base < Window

  def draw_actor_states(actor, x, y)

    ... # All the code you already have would go in here.

  end

end

Then you would override or alias the draw methods of Window_MenuStatus and Window_Target depending on how much rearranging you need to do with the draw code. Something like this:

Code:
class Window_MenuStatus < Window_Selectable

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

  # * Refresh                                                      !OVERRIDE!

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

  def refresh

    self.contents.clear

    @item_max = $game_party.actors.size

    for i in 0...$game_party.actors.size

      ... # Old code I don't want to reiterate.

      draw_actor_states(actor, x, y)

    end

  end

end

Again it is just a suggestion. If you want to continue from where you are the only problem you have, as mentioned above, is the instance variable @actor. In Window_Status there is one created so it's not a problem there, but with the other two window classes you will need to use the local variable actor.

Hope that helps. Good luck with it european_son! :thumb:
 
Thanks a lot! :grin: I was guessing that the problem had somehing to do with different types of variables. I'll try your approach and see if I can get it working...

EDIT: It's working now! :biggrin:
 

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