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.

RPG Maker XP - Printing Commas

I am printing variables in a custom window, but I can't get the commas to show up. If the variable is greater than 999, obviously, I would want the number to be comma separated.

#initialize the window
def self.initialize(x, y, w, h, opacity, back_opacity)
@window = Window_Base.new(x,y,w,h)
@window.contents = Bitmap.new(@window.width - 32, @window.height - 32)
@window.opacity = opacity
@window.back_opacity = back_opacity
end #method

#draw a single variable
def self.variable(x,y,w,h,i)
@window.contents.draw_text(x, y, w, h, "" + "" + "" + $game_variables.to_s, 0)
end #method

What do I need to do?

Thanks in advance for your help.
 
Adding the ' "" ' do nothing; it just adds an empty space character to the string. Try this:
Code:
 

#draw a single variable

def self.variable(x,y,w,h,i)

str = $game_variables[i].to_s

s = ""

for i in 0...str.to_s.length

if (str.to_s.length-i) % 3 == 0

s += ',' if str.to_s.length-i != 0

end

s += "#{str.to_s[str.to_s.length-i]}"

end

@window.contents.draw_text(x, y, w, h, s, 0)

end #method

 
 
Oh right, try this.
I was building the string backwards xD
Code:
def self.variable(x,y,w,h,i)

str = $game_variables[i].to_s

s = ""

for i in 0...str.to_s.length

    v = str.to_s[-(i+1)]

    if -i % 3 == 0

        s.insert(0,',') if -i != 0

    end

    s.insert(0,"#{v}")

end

@window.contents.draw_text(x, y, w, h, s, 0)

end #method
 

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