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.

Displaying the Value's Stored in Variables anywhere on the screen?

I've asked this a few times but i'm still pretty confused about it and everyone keeps telling me to go look at HUD scripts. There are tons of HUD scripts out there that people have made that handles the displaying of hp, mp, gold, str, e.t.c, i know that, but most of them are intended for a specific purpose such as displaying a window with HP and MP for a battle engine.

What i've been looking for is a very simple script that allows you to display whatever values are stored inside a variable with just simple text and no borders, backgrounds or anything to go along with it anywhere onto the screen.

Example: You made your own custom shop, and when you talk to the shop keeper you display a picture you made with all the stuff you can buy and on the bottom right of the picture you left an empty area for where you are going to display the amount of gold you have using this variable display script i'm looking for.

The easiest way to put it is that i'm looking for a script where you can literally go into the event editor and put a call script command along the lines of
DrawText(140,480,$game_variables[1].to_s) where the parameters are (x coord, y coord, variable value you want displayed).

I hope that makes some kind of sense. Any kind of help is appreciated, and i'll definately make sure to credit anyone who can really help me out with this in my game.
 
There you go.
Code:
class Scene_Map
  alias dargor_req_map_draw_text_initialize initialize
  alias dargor_req_map_draw_text_update update
  def initialize
    @text_bitmap = Bitmap.new(0,0,640,480)
    dargor_req_map_draw_text_initialize
    @text_bitmap.dispose
  end
  def update
    @text_bitmap.update
    dargor_req_map_draw_text_update
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_bitmap.clear if clear_bitmap
    @text_bitmap.draw_text(x,y,width,height,text,align)
  end
end

The only thing you have to do is to use a script call with the following line:
Code:
$scene.draw_text(x,y,width,height,text,align,clear_bitmap)
the 'clear_bitmap' argument is a boolean. When set to true, the text bitmap will get cleared before drawing the text. 'align' and 'clear_bitmap' can be omitted.

I made the script in 2 minutes and I'm at work so it's possible that it doesn't work at 100%.
Tell me if there's something wrong with it.

Take care!
-Dargor
 
wow that was quick thanks dargor, i'm gonna test it out. I have a quick question though. I noticed the class you made is called Scene_Map, and there's already a built in script with a class called Scene_Map. Do i put all the ruby code within the already made Scene_Map class, or is an entirely different class?
 
Oops sorry, i forgot that Bitmaps only need 2 arguments!
Code:
class Scene_Map
  alias dargor_req_map_draw_text_initialize initialize
  alias dargor_req_map_draw_text_update update
  def initialize
    @text_bitmap = Bitmap.new(640,480)
    dargor_req_map_draw_text_initialize
    @text_bitmap.dispose
  end
  def update
    @text_bitmap.update
    dargor_req_map_draw_text_update
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_bitmap.clear if clear_bitmap
    @text_bitmap.draw_text(x,y,width,height,text,align)
  end
end
 
You're welcome, I like to do that :)
undefined method 'update' ... for nilClass?
Try this.
Code:
class Scene_Map
  alias dargor_req_map_draw_text_main main
  alias dargor_req_map_draw_text_update update
  def main
    @text_bitmap = Bitmap.new(640,480)
    dargor_req_map_draw_text_main
    @text_bitmap.dispose
  end
  def update
    dargor_req_map_draw_text_update
    @text_bitmap.update
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_bitmap.clear if clear_bitmap
    @text_bitmap.draw_text(x,y,width,height,text,align)
  end
end
 
nah it's not liking your methods lol. Here's the full error it gave me now: undefined local variable or method 'dargor_req_map_draw_text_Initialize' for #<Scene_Map@text_bitmap=bitmap.....
 
it's ok, don't worry about it ;)
The problem is that I can't test it at work.
Code:
class Scene_Map
  alias dargor_req_map_draw_text_main main
  def main
    @text_bitmap = Bitmap.new(640,480)
    dargor_req_map_draw_text_main
    @text_bitmap.dispose
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_bitmap.clear if clear_bitmap
    @text_bitmap.draw_text(x,y,width,height,text,align)
  end
end


EDIT: I forgot to ask, is it for XP or VX???
 
Edit: This is in rpgmaker xp

Alright, so the good news is there are no more crashes before getting into the game so it likes your script. The bad news is, i'm still not able to get it to work. I tried two different things in event editor using call script. First i tried

$scene.draw_text(320,240,12,12,"HP:") 

and it didn't crash when activating it, but simply nothing happened. Nothing showed up on the screen. Then i tried

$scene.draw_text(320,240,12,12,"HP:"$game_variables[1].to_s,1,clear_bitmap)

and got a syntax error :(
 
Ok done. I have added a sprite to Scene_Map and its bitmap size is 640x480
Now the sprite can update properly (bitmaps cannot, that's why you had the undefined method 'update' error).
Code:
class Scene_Map
  alias dargor_req_draw_text_map_main main
  alias dargor_req_draw_text_map_update update
  def main
    text_viewport = Viewport.new(0,0,640,480)
    @text_sprite = RPG::Sprite.new(text_viewport)
    @text_sprite.bitmap = Bitmap.new(640,480)
    dargor_req_draw_text_map_main
    @text_sprite.dispose
  end
  def update
    dargor_req_draw_text_map_update
    @text_sprite.update
  end
  def draw_text(x,y,width,height,text,align=0,clear_bitmap=true)
    @text_sprite.bitmap.clear if clear_bitmap
    @text_sprite.bitmap.draw_text(x,y,width,height,text,align)
  end
end
 
Same result!
:cry: You think it's best if I you take a look at it when you get home since you have rpgmakerxp in front of you? My e-mail is thesousas2002@yahoo.com if you want to e-mail me a demo or example when you get a chance. Again i appreciate all the time and effort you put into helping me, and reguardless if i get this thing working or not i will still credit you. Tyvm
 

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