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.

my script isnt working right..should be simple fix

ok, so i moded my scence steps window to show the contents of variable 35, worked great. but then some one said that i should show a + or  - sign infront of it. because it is a purity meter. so this is what i did:(it works, meaning no error message, but when the value changes the number wont, infact i could make it change at all from -0)
#==============================================================================
# ** Window_Steps
#------------------------------------------------------------------------------
#  This window displays step count on the menu screen.
#==============================================================================

class Window_Steps < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
 
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, "Purity")
    self.contents.font.color = normal_color
    #text = $game_variables[0037]
    #puttogether = text1 + ":" + text2 + ";"
    if $game_variables[0035] > 0
    text1 = "+"
    text2 = $game_variables[0035]
    puttogether = text1.to_s + text2.to_s
  else
    text1 = "-"
    text2 = $game_variables[0035]
    puttogether = text1.to_s + text2.to_s
  end
    self.contents.draw_text(4, 32, 120, 32, puttogether, 2)
  end
end
 
can anyone please get it to show the contents of varible 35 and put a plus or minus sign when pos or neg, oh ya and neither when its 0
 

khmp

Sponsor

The value isn't drawing properly for you because you are including leading zeroes in front of the value you are attempting to get at index 35. What I mean is $game_variables[0035] doesn't exist so it's always zero. Just chop out those leading zeroes and just put in "35" minus the quotes of course.

Also about the plus and minus thingie. You only need to check for a positive number. A negative number converted to a string will already have the negative sign preceding it. I hope that helps you out. If not. The code is below.

Code:
#==============================================================================
# ** Window_Steps
#------------------------------------------------------------------------------
#  This window displays step count on the menu screen.
#==============================================================================

class Window_Steps < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(0, 0, 160, 96)
    self.contents = Bitmap.new(width - 32, height - 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.color = system_color
    self.contents.draw_text(4, 0, 120, 32, 'Purity')
    self.contents.font.color = normal_color
    
    # Create a variable to hold the number
    purity = $game_variables[35].to_s
    
    # If purity is positive add a plus sign in the front of it.
    # If purity is negative the negative sign is already included. 
    #   Ergo no need to check for 'less than zero' numbers.
    purity = '+' + purity if $game_variables[35] > 0
    
    # Or it can be laid out like this:
    # if $game_variables[35] > 0
    #   purity = '+' + purity
    # end
    
    self.contents.draw_text(4, 32, 120, 32, purity, 2)
  end
end

Good luck with it deathbethecost! :thumb:
 

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