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.

Display Number in HUD [RESOLVED]

regi

Sponsor

What's the coding for a picture and a number to appear corresponding to the number of an item in an inventory? The ID of the item and the coordinates on-screen should be easy to modify.
Okay, I'm having trouble with adding switches. Also, what's the code to show an icon? And how do I make it add an icon each time a certain switch is turned on?

How do I make the window appear/disappear for cutscenes? The $scene.my_window.appear/disappear still seems to have some bugs.
When I first turn the switch on (to make the HUD visible), it doesn't appear unless I use "$scene.my_window.appear". However, when I do that, there are no numbers. I have to make it disappear, then appear again to get them to appear. Also, when I go into my menu (or somewhere other than Scene_Map) and come back, it disappears! Here's the full script in case it helps. Thanks if you can help solve this.
 
Regimos":zhvx2np3 said:
EDIT: Still not sure how exactly to do it  :-\ I know basic coding and things for RGSS, but I just can't combine it into a script. Could anyone help write a short script for me with comments so I can learn how it's to be done? I just want a window to appear in the upper-left corner, show a picture, and show a number. I can probably tweak an already-existing script easier.

Btw... Synthesize, your link to ccoa's tutorial isn't working. There's an IPS driver error or something like that.

The link is working now, but the server appears to be unstable. If you can tweak an existing script easier, then use the code Charlie Lee posted and instead of drawing the gold, use the code I provided.
 
Here. The first part adds a window in Scene_Map and makes so that its update method is called at every map update.

Code:
class Scene_Map
  alias window_main main
  def main
    # create a window
    @my_window = My_Window.new
    #original call
    window_main
    @my_window.dispose
  end

  alias window_update update
  def update
    # Update my_window
    @my_window.update
    # Original call
    window_update
  end
end

The following defines the window. update does nothing unless the value to be displayed has changed, in that case it calls refresh.

Code:
class My_Window < Window_Base
  def initialize
    super(0, 0, 160, 64) # just put your preferred values here (x,y,width,height)
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    @pic = Sprite.new
    @pic.bitmap = RPG::Cache.picture("name of your picture")
    @pic.z = 101 
    # you can also play with @pic.x and @pic.y to positionate you pic
    refresh
  end

  def refresh
    self.contents.clear
    self.contents.draw_text(0, 0, 80, 32, $game_variables[5].to_s, 0)
    @value=$game_variables[5]
  end

  def update
    # call refresh if te value has changed
    if @value != $game_variables[5]
      refresh
    end
  end
end

Just play with numbers to meet your needs.
 

regi

Sponsor

Thanks, it works great! Only thing is, how do you make it disappear if you're in battle or the menu? Oh and shadowball, you don't have to send me your script anymore, thanks anyway.
 
You should add "attr_reader :my_window" just after Scene_Map, this lets you access to the window. Then use the commands
"$scene.my_window.visible=true" and "$scene.my_window.visible=false" (you have to be in the map while using these commands).

EDIT: to make things sure add @pic.visible=self.visible as the first line of My_Window's update method.
 

regi

Sponsor

EDIT: Okay, I'm still having trouble with adding the switches. How would I make the whole script run ONLY if switch 10 is on? Also, I originally planned to switch between 3 pictures with icons drawn in the picture, but now I think it'd be easier to just script it in. What's the code to show an icon? And how do I make it add an icon each time a certain script is turned on (putting it in initialize doesn't seem to work, because that's only when it's... initializing)?

Sorry if I'm asking a lot. Here's the script so far.

Code:
class Scene_Map
  
  attr_reader :my_window
  
  alias window_main main
  def main
    # create a window
    @my_window = My_Window.new
    #original call
    window_main
    @my_window.dispose
  end

  alias window_update update
  def update
    # Update my_window
    @my_window.update
    # Original call
    window_update
  end
end

class My_Window < Window_Base
  def initialize
    super(0, 0, 160, 64) # (x,y,width,height)
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    @pic = Sprite.new
    @pic.bitmap = RPG::Cache.picture("itemshud")
    @pic.z = 101
    # you can also play with @pic.x and @pic.y to position your pic
    refresh
  end

  def refresh
      self.contents.clear
    if $game_switches[10] == true
      self.contents.draw_text(0, 0, 80, 32, $game_party.item_number(41).to_s, 0)
      @value=$game_party.item_number(41)
    end
    if $game_switches[20] == true
      self.contents.draw_text(50, 0, 80, 32, $game_party.item_number(49).to_s, 0)
      @value2=$game_party.item_number(49)
    end
  end

  def update
    if $game_switches[10] == true
      # call refresh if the value has changed
      if @value != $game_party.item_number(41)
        refresh
      end
    end
    if $game_switches[20] == true
      # call refresh if the value has changed
      if @value2 != $game_party.item_number(49)
        refresh
      end
    end
  end
  
  def dispose
    @pic.dispose
    super
  end
  
end
  
end
 
The code to display an icon is not much different from that to display a picture. Isn't an icon a picture? Use RPG::Cache.icon("icon_name")

So you can use this as a starting point:
Code:
class My_Window < Window_Base
  def initialize
    super(0, 0, 160, 64) # (x,y,width,height)
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    @pic = Sprite.new
    @pic.bitmap = RPG::Cache.picture("itemshud")
    @pic.z = 101
    # you can also play with @pic.x and @pic.y to position your pic
    @icon1 = Sprite.new
    @icon1.bitmap = RPG::Cache.icon("icon1")
    @icon1.z = 101
    @icon1.visible=false
    # you can also play with @icon1.x and @icon1.y to position your icon
    @icon2 = Sprite.new
    @icon2.bitmap = RPG::Cache.icon("icon2")
    @icon2.z = 101
    @icon2.visible=false
    # you can also play with @icon2.x and @icon2.y to position your icon
    @icon3 = Sprite.new
    @icon3.bitmap = RPG::Cache.icon("icon3")
    @icon3.z = 101
    @icon3.visible=false
    # you can also play with @icon3.x and @icon3.y to position your icon
    refresh
  end

def refresh
  @icon1.visible=false
  @icon2.visible=false
  @icon3.visible=false
  self.contents.clear
    if $game_switches[10] == true
      self.contents.draw_text(0, 0, 80, 32, $game_party.item_number(41).to_s, 0)
      @value=$game_party.item_number(41)
      @icon1.visible=true
    end
    if $game_switches[20] == true
      self.contents.draw_text(50, 0, 80, 32, $game_party.item_number(49).to_s, 0)
      @value2=$game_party.item_number(49)
      @icon2.visible=true
    end
    # Do the same for you third value
  end

  def update
    if (@value != $game_party.item_number(41)) or
    (@value2 != $game_party.item_number(49)) or
    (third condition)
      refresh
    end
  end
end
 

regi

Sponsor

Perfect :) Using the visible or invisible command is probably the best way to work this, that was the problem I couldn't figure out how to work. And I figured an icon would be something similar to a picture, just checking out the coding.

I can probably configure the rest myself now, thanks for all your help: shadowball, Synthesize, and Charlie Lee!
 

regi

Sponsor

Bumping with new question. How do I get the window to appear/disappear for cutscenes?

Here's the full script in case it helps.
Code:
class Scene_Map
  
  attr_reader :my_window
  
  alias window_main main
  def main
    # create a window
    @my_window = My_Window.new
    #original call
    window_main
    @my_window.dispose
  end

  alias window_update update
  def update
    # Update my_window
    @my_window.update
    # Original call
    window_update
  end
end

class My_Window < Window_Base
  def initialize
    super(0, 0, 160, 64) # (x,y,width,height)
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    @pic = Sprite.new
    @pic.bitmap = RPG::Cache.picture("itemshud")
    @pic.z = 101
    @pic.visible=false
    @icon1 = Sprite.new
    @icon1.bitmap = RPG::Cache.icon("nut")
    @icon1.x = 12
    @icon1.y = 15
    @icon1.z = 101
    @icon1.visible=false
    # play with @icon1.x and @icon1.y to position your icon
    @icon2 = Sprite.new
    @icon2.bitmap = RPG::Cache.icon("bomb")
    @icon2.x = 65
    @icon2.y = 15
    @icon2.z = 101
    @icon2.visible=false
    # play with @icon2.x and @icon2.y to position your icon
    @icon3 = Sprite.new
    @icon3.bitmap = RPG::Cache.icon("gauntlets")
    @icon3.x = 118
    @icon3.y = 15
    @icon3.z = 101
    @icon3.visible=false
    # play with @icon3.x and @icon3.y to position your icon
    refresh
  end

def refresh
  @icon1.visible=false
  @icon2.visible=false
  @icon3.visible=false
  @pic.visible=false
  self.contents.clear
    if $game_switches[10] == true
      self.contents.draw_text(0, 0, 80, 32, $game_party.item_number(41).to_s, 0)
      @value=$game_party.item_number(41)
      @icon1.visible=true
      @pic.visible=true
    end
    if $game_switches[20] == true
      self.contents.draw_text(50, 0, 80, 32, $game_party.item_number(49).to_s, 0)
      @value2=$game_party.item_number(49)
      @icon2.visible=true
    end
    if $game_switches[39] == true
      @switch1=$game_switches[39]
      @icon3.visible=true
    end
  end

  def update
    if (@value != $game_party.item_number(41)) or
    (@value2 != $game_party.item_number(49)) or
    (@switch1 != $game_switches[39])
      refresh
    end
  end
  
  def dispose
    @pic.dispose
    @icon1.dispose
    @icon2.dispose
    @icon3.dispose
    super
  end
  
end
 
Oh yes, that's right (it's because the pictures are not drawn on the window's bitmap), I forgot about the pictures.
Maybe it's better to do a couple of commands in the My_Window class then:
Code:
def appear
  self.visible=true
  refresh
end

def disappear
  self.visible=false
  <all your icons and pictures>.visible=false
end

You can also insert a line inside the refresh method that simply returns without doing anything if self.visible is true. That is for preventing the pics from reappearing if the conditions in update are met.

And then you call $scene.my_window.appear and $scene.my_window.disappear
 

regi

Sponsor

Ehhmm... bump.
I just noticed, there are still more bugs to be found.

1. When I first make the HUD visible (using $scene.my_window.appear) the numbers don't show, only the picture and the icons. I have to make the HUD disappear, then reappear again for the numbers to show.
2. If I go into a scene other than Scene_Map (the menu, battle, etc.) and come back out, the HUD disappears.

Here's the full script.
Code:
class Scene_Map
  
  attr_reader :my_window
  
  alias window_main main
  def main
    # create a window
    @my_window = My_Window.new
    #original call
    window_main
    @my_window.dispose
  end

  alias window_update update
  def update
    # Update my_window
    @my_window.update
    # Original call
    window_update
  end
end

class My_Window < Window_Base
  def initialize
    super(0, 0, 160, 64) # (x,y,width,height)
    self.opacity=0
    self.contents = Bitmap.new(width - 32, height - 32)
    @pic = Sprite.new
    @pic.bitmap = RPG::Cache.picture("itemshud")
    @pic.z = 101
    @pic.visible=false
    @icon1 = Sprite.new
    @icon1.bitmap = RPG::Cache.icon("nut")
    @icon1.x = 12
    @icon1.y = 15
    @icon1.z = 101
    @icon1.visible=false
    # play with @icon1.x and @icon1.y to position your icon
    @icon2 = Sprite.new
    @icon2.bitmap = RPG::Cache.icon("bomb")
    @icon2.x = 65
    @icon2.y = 15
    @icon2.z = 101
    @icon2.visible=false
    # play with @icon2.x and @icon2.y to position your icon
    @icon3 = Sprite.new
    @icon3.bitmap = RPG::Cache.icon("gauntlets")
    @icon3.x = 118
    @icon3.y = 15
    @icon3.z = 101
    @icon3.visible=false
    # play with @icon3.x and @icon3.y to position your icon
    refresh
  end

  def refresh
    if self.visible == true
      return
    end
    
    @pic.visible=false
    @icon1.visible=false
    @icon2.visible=false
    @icon3.visible=false
    self.contents.clear
    if $game_switches[10] == true
      self.contents.draw_text(0, 0, 80, 32, $game_party.item_number(41).to_s, 0)
      @value=$game_party.item_number(41)
      @icon1.visible=true
      @pic.visible=true
    end
    if $game_switches[20] == true
      self.contents.draw_text(50, 0, 80, 32, $game_party.item_number(49).to_s, 0)
      @value2=$game_party.item_number(49)
      @icon2.visible=true
    end
    if $game_switches[39] == true
      @switch1=$game_switches[39]
      @icon3.visible=true
    end
  end

  def update
    if (@value != $game_party.item_number(41)) or
    (@value2 != $game_party.item_number(49)) or
    (@switch1 != $game_switches[39])
      refresh
    end
  end
  
  def appear
    self.visible=true
    @pic.visible=true
    @icon1.visible=true
    @icon2.visible=true
    @icon3.visible=true
    refresh
  end
  
  def disappear
    self.visible=false
    @pic.visible=false
    @icon1.visible=false
    @icon2.visible=false
    @icon3.visible=false
  end
  
  def dispose
    @pic.dispose
    @icon1.dispose
    @icon2.dispose
    @icon3.dispose
    super
  end
  
end

Thanks.
 
Oh, i made a typo in the previous post.
"You can also insert a line inside the refresh method that simply returns without doing anything if self.visible is true."
It was:
"You can also insert a line inside the refresh method that simply returns without doing anything if self.visible is false.

That happens when you write at 3:00 am...
Fix this first and then tell me if you still have those problems.
 

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