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.

Not updating...

I'm using RMVX and I have a window that wont update. I'm not perfect at scripting, and I need help. I have the window in Scene_Map. Also I just tested the gold window that I moved there and it wont update either. It will only update if I go to a different scene. Here are the scripts.

Gold Window
Code:
#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays the amount of gold.
#==============================================================================

class Window_Gold < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x : window X coordinate
  #     y : window Y coordinate
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    draw_currency_value($game_party.gold, 4, 0, 120)
  end
end
Time Window -I didn't change any comments. Waste of time.
Code:
#==============================================================================
# ** Window_Gold
#------------------------------------------------------------------------------
#  This window displays the amount of gold.
#==============================================================================

class Window_Time < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     x : window X coordinate
  #     y : window Y coordinate
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    $game_variables[2]
    $game_variables[3]
    self.contents.clear
    draw_currency_value($game_variables[21], 4, 0, 20)
    draw_currency_value($game_variables[22], 4, 0, 50)
  end
end
Scene_Map
Code:
#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs the map screen processing.
#==============================================================================

class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # * Start processing
  #--------------------------------------------------------------------------
  def start
    super
    $game_map.refresh
    @spriteset = Spriteset_Map.new
    @message_window = Window_Message.new
    @time_window = Window_Time.new(0, 0)
    @gold_window = Window_Gold.new(0, 360)
  end
  #--------------------------------------------------------------------------
  # * Execute Transition
  #--------------------------------------------------------------------------
  def perform_transition
    if Graphics.brightness == 0       # After battle or loading, etc.
      fadein(30)
    else                              # Restoration from menu, etc.
      Graphics.transition(15)
    end
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    if $scene.is_a?(Scene_Battle)     # If switching to battle screen
      @spriteset.dispose_characters   # Hide characters for background creation
    end
    snapshot_for_background
    @spriteset.dispose
    @message_window.dispose
    @time_window.dispose
    @gold_window.dispose
    if $scene.is_a?(Scene_Battle)     # If switching to battle screen
      perform_battle_transition       # Execute pre-battle transition
    end
  end
  #--------------------------------------------------------------------------
  # * Basic Update Processing
  #--------------------------------------------------------------------------
  def update_basic
    Graphics.update                   # Update game screen
    Input.update                      # Update input information
    $game_map.update                  # Update map
    @spriteset.update                 # Update sprite set
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    $game_map.interpreter.update      # Update interpreter
    $game_map.update                  # Update map
    $game_player.update               # Update player
    $game_system.update               # Update timer
    @spriteset.update                 # Update sprite set
    @message_window.update            # Update message window
    @time_window.update
    @gold_window.update
    unless $game_message.visible      # Unless displaying a message
      update_transfer_player
      update_encounter
      update_call_menu
      update_call_debug
      update_scene_change
    end
  end
  #--------------------------------------------------------------------------
  # * Fade In Screen
  #     duration : time
  #    If you use Graphics.fadeout directly on the map screen, a number of
  #    problems can occur, such as weather effects and parallax  scrolling
  #    being stopped. So instead, perform a dynamic fade-in.
  #--------------------------------------------------------------------------
  def fadein(duration)
    Graphics.transition(0)
    for i in 0..duration-1
      Graphics.brightness = 255 * i / duration
      update_basic
    end
    Graphics.brightness = 255
  end
  #--------------------------------------------------------------------------
  # * Fade Out Screen
  #     duration : time
  #    As with the fadein above, Graphics.fadein is not used directly.
  #--------------------------------------------------------------------------
  def fadeout(duration)
    Graphics.transition(0)
    for i in 0..duration-1
      Graphics.brightness = 255 - 255 * i / duration
      update_basic
    end
    Graphics.brightness = 0
  end
  #--------------------------------------------------------------------------
  # * Player Transfer  Processing
  #--------------------------------------------------------------------------
  def update_transfer_player
    return unless $game_player.transfer?
    fade = (Graphics.brightness > 0)
    fadeout(30) if fade
    @spriteset.dispose              # Dispose of sprite set
    $game_player.perform_transfer   # Execute player transfer
    $game_map.autoplay              # Automatically switch BGM and BGS
    $game_map.update
    Graphics.wait(15)
    @spriteset = Spriteset_Map.new  # Recreate sprite set
    fadein(30) if fade
    Input.update
  end
  #--------------------------------------------------------------------------
  # * Encounter Processing
  #--------------------------------------------------------------------------
  def update_encounter
    return if $game_player.encounter_count > 0        # Check steps
    return if $game_map.interpreter.running?          # Event being executed?
    return if $game_system.encounter_disabled         # Encounters forbidden?
    troop_id = $game_player.make_encounter_troop_id   # Determine troop
    return if $data_troops[troop_id] == nil           # Troop is invalid?
    $game_troop.setup(troop_id)
    $game_troop.can_escape = true
    $game_temp.battle_proc = nil
    $game_temp.next_scene = "battle"
    preemptive_or_surprise
  end
  #--------------------------------------------------------------------------
  # * Determine Preemptive Strike and Surprise Attack Chance
  #--------------------------------------------------------------------------
  def preemptive_or_surprise
    actors_agi = $game_party.average_agi
    enemies_agi = $game_troop.average_agi
    if actors_agi >= enemies_agi
      percent_preemptive = 5
      percent_surprise = 3
    else
      percent_preemptive = 3
      percent_surprise = 5
    end
    if rand(100) < percent_preemptive
      $game_troop.preemptive = true
    elsif rand(100) < percent_surprise
      $game_troop.surprise = true
    end
  end
  #--------------------------------------------------------------------------
  # * Determine if Menu is Called due to Cancel Button
  #--------------------------------------------------------------------------
  def update_call_menu
    if Input.trigger?(Input::B)
      return if $game_map.interpreter.running?        # Event being executed?
      return if $game_system.menu_disabled            # Menu forbidden?
      $game_temp.menu_beep = true                     # Set SE play flag
      $game_temp.next_scene = "menu"
    end
  end
  #--------------------------------------------------------------------------
  # * Determine Bug Call Due to F9 key
  #--------------------------------------------------------------------------
  def update_call_debug
    if $TEST and Input.press?(Input::F9)    # F9 key during test play
      $game_temp.next_scene = "debug"
    end
  end
  #--------------------------------------------------------------------------
  # * Execute Screen Switch
  #--------------------------------------------------------------------------
  def update_scene_change
    return if $game_player.moving?    # Is player moving?
    case $game_temp.next_scene
    when "battle"
      call_battle
    when "shop"
      call_shop
    when "name"
      call_name
    when "menu"
      call_menu
    when "save"
      call_save
    when "debug"
      call_debug
    when "gameover"
      call_gameover
    when "title"
      call_title
    else
      $game_temp.next_scene = nil
    end
  end
  #--------------------------------------------------------------------------
  # * Switch to Battle Screen
  #--------------------------------------------------------------------------
  def call_battle
    @spriteset.update
    Graphics.update
    $game_player.make_encounter_count
    $game_player.straighten
    $game_temp.map_bgm = RPG::BGM.last
    $game_temp.map_bgs = RPG::BGS.last
    RPG::BGM.stop
    RPG::BGS.stop
    Sound.play_battle_start
    $game_system.battle_bgm.play
    $game_temp.next_scene = nil
    $scene = Scene_Battle.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Shop Screen
  #--------------------------------------------------------------------------
  def call_shop
    $game_temp.next_scene = nil
    $scene = Scene_Shop.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Name Input Screen
  #--------------------------------------------------------------------------
  def call_name
    $game_temp.next_scene = nil
    $scene = Scene_Name.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Menu Screen
  #--------------------------------------------------------------------------
  def call_menu
    if $game_temp.menu_beep
      Sound.play_decision
      $game_temp.menu_beep = false
    end
    $game_temp.next_scene = nil
    $scene = Scene_Menu.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Save Screen
  #--------------------------------------------------------------------------
  def call_save
    $game_temp.next_scene = nil
    $scene = Scene_File.new(true, false, true)
  end
  #--------------------------------------------------------------------------
  # * Switch to Debug Screen
  #--------------------------------------------------------------------------
  def call_debug
    Sound.play_decision
    $game_temp.next_scene = nil
    $scene = Scene_Debug.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Game Over Screen
  #--------------------------------------------------------------------------
  def call_gameover
    $game_temp.next_scene = nil
    $scene = Scene_Gameover.new
  end
  #--------------------------------------------------------------------------
  # * Switch to Title Screen
  #--------------------------------------------------------------------------
  def call_title
    $game_temp.next_scene = nil
    $scene = Scene_Title.new
    fadeout(60)
  end
  #--------------------------------------------------------------------------
  # * Execute Pre-battle Transition
  #--------------------------------------------------------------------------
  def perform_battle_transition
    Graphics.transition(80, "Graphics/System/BattleStart", 80)
    Graphics.freeze
  end
end

P.S. If you can, help put a colon in the time window so it's like a clock.
 

poccil

Sponsor

You must also override the update method of each window to call the
refresh method if necessary.  Here are the two versions of the classes
with the update methods added.  In addition, I've added a feature to make
the time window optionally display a 24-hour or 12-hour clock.

Essentially, you store the variables within refresh in a variable beginning
with "old".  Then you check the old variables with the current variables
whenever the update method is called.

Code:
class Window_Gold < Window_Base
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    refresh
  end
  def refresh
    self.contents.clear
    @oldGold=$game_party.gold
    draw_currency_value(@oldGold, 4, 0, 120)
  end
  def update
    super
    refresh if @oldGold!=$game_party.gold
  end
end

class Window_Time < Window_Base
  def initialize(x, y)
    super(x, y, 160, WLH + 32)
    # Set to true for a 24-hour clock, or false
    # for a 12-hour clock.  
    @twentyFourHours=true
    refresh
  end
  def refresh
    self.contents.clear
    @oldHour=$game_variables[21]
    @oldMinute=$game_variables[22]
    time=""
    if @twentyFourHours
     time=sprintf("%02d:%02d",@oldHour,@oldMinute)
    else
     time=sprintf("%02d:%02d %s",[12,1,2,3,4,5,6,7,8,9,10,11][@oldHour%12],@oldMinute,
           @oldHour<12 ? "AM" : "PM")
    end
    self.contents.draw_text(0,0,self.contents.width,self.contents.height,time,1)
  end
  def update
    super
    # Call refresh if any variables have changed
    refresh if @oldHour!=$game_variables[21] || @oldMinute!=$game_variables[22]
  end
end
 

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