Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Request] help changing existing script

Started by Ocelot0222, April 13, 2010, 11:43:19 PM

0 Members and 1 Guest are viewing this topic.

Ocelot0222

How would i go about changing the script for Window_PlayTime to show a variable? I'm trying to use that space to show karma, and i managed to replace "play time" with "karma" do not know how to call the variable in the script. what would i have to change to fix this from the standard script - ==============================================================================
# ** Window_PlayTime
#------------------------------------------------------------------------------
#  This window displays play time on the menu screen.
#==============================================================================

class Window_ < 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, "Play Time")
    @total_sec = Graphics.frame_count / Graphics.frame_rate
    hour = @total_sec / 60 / 60
    min = @total_sec / 60 % 60
    sec = @total_sec % 60
    text = sprintf("%02d:%02d:%02d", hour, min, sec)
    self.contents.font.color = normal_color
    self.contents.draw_text(4, 32, 120, 32, text, 2)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    if Graphics.frame_count / Graphics.frame_rate != @total_sec
      refresh
    end
  end
end

modern algebra

Well, you should give the class a more meaningful name than Window_ but the code for retrieving the value of an eventing variable is $game_variables[n], where n is the ID of the variable you want to get. To draw it as a string, you would need to convert it with the $game_variables[n].to_s. So, something like this:

#==============================================================================
# ** Window_Karma
#------------------------------------------------------------------------------
#  This window displays play time on the menu screen.
#==============================================================================

class Window_Karma < 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
   @karma_variable = $game_variables[1]
   self.contents.font.color = system_color
   self.contents.draw_text(4, 0, 120, 32, "Karma")
   self.contents.font.color = normal_color
   self.contents.draw_text(4, 32, 120, 32, @karma_variable.to_s, 2)
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 def update
   super
   if @karma_variable != $game_variables[1]
     refresh
   end
 end
end


Should do it. Change the 1 in $game_variables[1] to whatever the ID is of the variable that holds karma.

I left the update method in on the off chance you want to use this outside the menu, where there is a possibility of the value of the variable changing. It is probably useless if you want to use it in the menu.