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 Variables in Menu

I need help finding a way to show variables in the menu, because my game is one-character based and he has other non-combat skills that I want to show in the menu.
 
self.contents.draw_text(x, y, width, height, $game_variables[z])

I may be wrong with the arguments there, I haven't used RGSS in a while. But that's the jist of it. z here is the number of a game variable.
 
It's actually...
[rgss]self.contents.draw_text(x, y, width, height, $game_variables[n], align=0)
[/rgss]
It has to be called from within a Window instance to be able to access 'contents'. Also, the align attribute is completely optional, however should be mentioned as an important part of the method.

</smartass>
 
BlueScope":2o2cpe86 said:
It's actually...
[rgss]self.contents.draw_text(x, y, width, height, $game_variables[n], align=0)
[/rgss]
It has to be called from within a Window instance to be able to access 'contents'. Also, the align attribute is completely optional, however should be mentioned as an important part of the method.

</smartass>

So would [rgss]self.contents.draw_text(1, 1, 100, 100, $game_variables[1], align=0)
[/rgss] Work? Also, how do I call these? Can I do many at once? Even make it into the HUD?
 
While your line would work (except for the align=0, more to that later), it's not nearly as efficient as it could be. At the very moment, you will create a rect that is 1px from the left, 1px from the top, 100px each wide and tall, in other words, totally pointless for whatever drawing purpose. The default drawing in RMXP's windows assumes 4px from the left, 0px from the top, a width depending on the window width, and a height of 32 for a single text line... in other words:
Code:
self.contents.draw_text(4, 0, self-width-40, 32, $game_variables[1].to_s)
I added the .to_s for converting the integer into a string before output, which you have to do, I think. Also for the align, my way of writing it was a mere respresentation of the definition, as there's somewhere in the hardcoded, hidden scripts a line that looks like this:
Code:
def draw_text(x, y, width, height, text, align=0) # actually, as this method supports rects afaik, it should look a bit different... however, this is about align right now!
The '=0' essentially means that if you don't put anything, 0 will be chosen by default. That means, if you want your text to be aligned left in the rect you specify, don't put any number there for efficiency of your script. However, if you do want to put a number there, like 1 for centering or 2 for right justify, you don't write 'align=1', but simply '1'.

For many at once, yeah, you can do how many you want to have. You should be careful to not put these into update definitions, but refresh definitions though, as it's a comparatively slow method that will soon make your game lag if called every frame. And yeah, you can of course include it in a HUD (for that purpose you might want to check out Yeyinde's Beginner's HUD Tutorial, which is really beginner's level and should give you a very good idea about stuff really), as you can include it in every window you draw. Every text you see that already is in the game has been drawn with this method, so you see it's quite universal.
 

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