RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Request] help changing existing script

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 83
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

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
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:

Code: [Select]
#==============================================================================
# ** 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.