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.

Trouble with draw_text

Ok... I'm making a script, of a window, with lots of text drawn. I tested each of the variables with print, and they all have a value (even if that value is " " or "0").

But it doesn't draw any text.

Note: I commented out the armour lines as I'm having trouble with the syntax, if anyone could help me with that it'd be great :)

Code:
class Window_HudStatline < Window_Base
  def initialize
    super(373-16, 57-16, 200, 200)
    self.contents = Bitmap.new(width, height)
    self.opacity = 0
    self.z = 9999
    x = 16
    y = 16
    refresh
  end
  def refresh
    self.contents.clear
    @name = $user_name_pl
    actor = $game_party.actors[0]
    @weapon = $data_weapons[actor.weapon_id].name
    @armourstat = ""
    #@armour = $data_armors[actor.armor2_id].name
    #@armourstat = $data_armors[actor.armor1_id].pdef
    #@armourstat += $data_armors[actor.armor2_id].pdef
    #@armourstat += $data_armors[actor.armor3_id].pdef
    #@armourstat += $data_armors[actor.armor4_id].pdef
    @weaponbase = $data_weapons[actor.weapon_id].atk
    @weaponrand = $data_weapons[actor.weapon_id].str_plus
    @weaponperc = $data_weapons[actor.weapon_id].agi_plus
    @weaponspee = $data_weapons[actor.weapon_id].mdef
    
    a = actor.maxhp + actor.maxsp
    b = a / 2
    c = b - 9
    
    @statline = "#{@weaponbase} "
    @statline += "#{@weaponrand} "
    @statline += "#{@weaponbase} "
    @statline += "#{@weaponspee} "
    @statline += "#{@armourstat} "
    @statline += "#{c}"
    @statline = @statline.to_s
    
    self.contents.draw_text(x, y, 100, 20, @name.to_s)
    self.contents.draw_text(x, y+16, 100, 20, "Weapon: " + @weapon.to_s)
    self.contents.draw_text(x, y+32, 100, 20, "Armour: " + @armour.to_s)
    self.contents.draw_text(x+10, y+61, 100, 20, @statline)
  end
end

What this does is draws a window which looks like this:

Daniel
Weapon: Bronze Sword
Armour: Bronze Armour

B | R | % | S | A- | Lv
1 | 3 | 70| 3 | 2  | 1

(The letters and lines are to be added on by a graphical overlay).
 

khmp

Sponsor

You created x and y in the initialize locally. So to actually fix your problem put an "@" in front of all those instances of x and y.

Good luck with it Wyatt! :afro:
 
well, as far as I've learned about rgss, you only set a value to a variable or anything else in the same method that will use it, especially if you're defining and redefining a value for a x or y-axis.
 
What's actually happening is that the "x" and "y" values in the refresh method aren't defined as variables in that scope - so the interpreter goes up the stack and finds methods for both of them, which return the window's position on the screen. So yes, you can either convert "x" and "y" to instance variables or define them in the refresh method instead. I'd recommend you name them something different as well - regardless of the solution you opt for - in order to cause less confusion.
 

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