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.

Tiny snippet required please for on-screen variable

Hi, All I need is for variable no. 10 to display in between the word Charm and the % symbol.  It doesn't need to actually be shown as a percentage though, literally just the variable value.  This is due to me only allowing that variable to range between 0 and 100.  It only appears when switch 1 is ON.  Goes away when switch 1 is OFF.

Thanks for looking at this and I can credit you should you desire it.

http://img370.imageshack.us/img370/2594/requestby6.png[/img]
 
You can use this line to draw variable 10:
Code:
self.contents.draw_text(x, y, width, height, $game_variables[10].to_s, align)

X coordinate within the window bitmap to draw the text, the Y coordinate within the window bitmap to draw the text, the width of the space alloted for the text, the height of the space allotted for the text, and the text itself.

  x - the x position of the variable within the window bitmap to draw the text.
  y - the y position of the variable within the window bitmap to draw the text.
  width - The width of the space allotted for the text. 32 is the lowest, and it should probably
             be something higher or else the number will look squashed when it
             reaches 100.
  height - the height of the space allotted for the text. 32 is the lowest.
  align - 0 = left, 1 = center, 2 = right.

And to display it when switch 1 is on, you put this before it:
Code:
if $game_switches[1] == true

So for an example, it can look something like this:
Code:
if $game_switches[1] == true
self.contents.draw_text(50, -10, 42, 42, $game_variables[10].to_s, 0)
end

Good luck! :thumb:

Over and out - Gando
 
Ok thanks for helping there Gando but that alone doesn't work as a standalone script and I don't know anything about scripting.  Alone this gives me a no method error nilclass etc.  I do understand how to fill in the coords etc though, just not set it up.
 
Hmm..  okay,
I guess i can write a small HUD for you :wink:
Paste this in an empty section above main:
Code:
#==============================================================================
# ** Window_HUD
#------------------------------------------------------------------------------
#
# Variable - Change this number if you want to have another variable displayed
#            instead of variable 10.
#
#==============================================================================
class Window_HUD < Window_Base
  Variable = 10
  
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  #
  #  self.opacity - this is the opacity of the window, (0-255).
  #                     0 means that the window is fully transparent.
  #
  #  self.visible = false  - this will make the window invisible by default.
  #                              Further down you will see the setup that will
  #                              make the window show when switch 1 is ON.
  #--------------------------------------------------------------------------
  def initialize
    super(490, 0, 150, 70)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    self.visible = false
    @variable = $game_variables[Variable]
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  #
  #  Here you can change this line to choose where on the screen the variable
  #  should be displayed.
  #
  #  You should change this line: 
  #  self.contents.draw_text(50, -10, 52, 52, @variable.to_s, 0)
  #
  #  Here is the same line but with explination on what everything does:
  #  self.contents.draw_text(x, y, width, height, @variable.to_s, align)
  #
  #  x - the x position of the variable
  #  y - the y position of the variable
  #  width - the width of the variable, 32 is the lowest, and it should probably
  #          be something higher or else the number will look squashed when it
  #          reaches 100.
  #  height - the height of the variable. 32 is the lowest.
  #  align - the alignment, 0 = left, 1 = center, 2 = right.
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.draw_text(50, -10, 52, 52, $game_variables[10].to_s, 0)
  end
  def update
    super
    refresh if @variable = $game_variables[Variable] 
  end
end
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
# if $game_switches[1] == true  - this line is there to make sure that the va
#==============================================================================
class Scene_Map
  alias yourhud_main main
  alias yourhud_update update
  def main
    @yourhud = Window_HUD.new
    yourhud_main
    @yourhud.dispose
  end
  def update
    if $game_switches[1] == true
      @yourhud.visible = true
    else
      @yourhud.visible = false      
    end
    @yourhud.update
    yourhud_update
  end
end

I've commented the script so that you can understand what to change so that it suits your needs.
If you turn switch 1 on, it will display the variable in the right corner, and you can change the x and y position the way i explained in the last post.  :thumb:

Over and out - Gando
 
Ok buddy, thanks.  I'll try it and edit this if I have any difficulties.  Oh and very thorough may I add, if everyone commented like that!

EDIT:

Yeah thanks man, it works perfectly.  I'll be sure to credit you for helping me out there. 
 

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