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.

Data Printing Help [New Problems!]

I'm attempting to create a custom window that will print a specific acro's sp/maxsp (and will update it as it changes in runtime). I copied over the methor draw_actor_sp from Window_Base and tried to change it, but I really don't know enough about ruby to know in what ways to change it to make it print Actor 5's sp/maxsp specifically.

Can anyone give me some code for that. I really don't want to post what I have now because it's a mess and probably won't tell you anything.
 
Okay... I looked through that, and anything that looks like it MIGHT have what I need in it is a broken link.

I just need to know how to print something from the data system (or even a game variable) in a window. I've tried this:

Code:
 

self.contents.draw_text(0, 0, 50, 32, $game_variables[1], 2)

 

But, it seems that I have to have a string in there, not a variable to output. I can set a variable equal to sp/maxsp, but I can't figure out how to print either one.
 
First, what you quoted in your last post: What you have to do is convert the variable into a string. It now is an integer, meaning it can't be processed as outputable string, so you gotta use:

[rgss]self.contents.draw_text(0, 0, 50, 32, $game_variables[1].to_s, 2)
[/rgss]

There's other conversion methods as well, but the most common you'll need are to_s, to_i and to_a


For your topic question, you don't need to copy draw_actor_sp anywhere - it's inside Window_Base to be used from there. Check any window's class initialization line. It should say 'class Window_[window's name] < Window_Base', with the exception of Window_Base itself, which has Window. That's called a superclass, meaning you can use all methods that last mentioned class has in your current class as well.
Knowing that, you can take like Window_Gold as a basis so you don't have to write anything by yourself. Then just replace the drawing gold part with draw_actor_sp, and you'Re set already. It's dead-easy once you know what you have to do.
 
LOL! All right, thanks a lot! The reason I had copied the method was because I wanted to see if I could change it to print the sp of a specific actor because I didn't see that the parameters could do that, but the variable thing will work fine! Thanks again!

EDIT: Okay, I've done all I could, and I've even compared it to some of the other windows like gold and playtime, but this code seems to be causing a problem with the main loop. I'm getting an undefined meoth 'main' on line 14, wich is just says $scene.main. I though this was bcause my code has no main method, but the other's don't either. Here's what I've got:

Code:
 

class Window_Energy < Window_Base

  def initialize

    super(0, 0, 200, 96)

    self.contents = Bitmap.new(width - 32, height - 32)

    refresh

  end

  

  def refresh

    self.contents.clear

    @sp = $game_variables[1].to_s

    @maxsp = $game_variables[2].to_s

    self.contents.draw_text(0, 0, 200, 32, "Energy", 1)

    self.contents.draw_text(0, 32, 90, 32, @sp, 2)

    self.contents.draw_text(90, 32, 20, 32, "/", 1)

    self.contents.draw_text(110, 32, 90, 32, @maxsp)

  end

  

  def update

    super

    if $game_variables[1] != @sp || $game_variables[2] != @maxsp

      refresh

    end

  end

end

 
 
In Scene_Map

here is a simple hud code:

[rgss] 
class Scene_Map
  alias smap_main main
  alias smap_update update
  def main
    @hud = Window_Energy.new
    smap_main
    @hud.dispose
  end
  def update
    @hud.update
    if $game_player.y < 3
      @hud.opacity = 160
    else
      @hud.opacity = 235
    end
    smap_update
  end
end
 
 
[/rgss]
 
oh, then at the beginning of your game, in an event put in
Call Script: $scene.hud.visible = false

and copy and paste this above main:

[rgss] 
class Scene_Map
  attr_accessor :hud
end
 
[/rgss]

and when you want to pop it up, use an event and do
Call Script: $scene.hud.visible = true

and to make it invisible, use the same call script as in the
intro of your game.
 

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