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.

Help On a existing script

VCA

Member

I don't know if I'm the right place to post this kind of topic someone correct if I'm in the wrong place. There was this script made or given to me by Brewmeister(heres the link viewtopic.php?f=12&t=66899), the script had some bugs which i'm about to explain. The one bug that concerns me is why the pic window doesn't goes away, i tryed to fix it myself but no luck. here some pics to help explain my cause.

At first
ScreenHunter_02Oct1518.png


In the RED You see that's the normal way the pic image appears.
But then when I close or press the Cancel button (you know to exit the item screen) then this happens.

ScreenHunter_01Oct1518.png


For some reason, the pic window (In the RED) is still there even though I already exit the item screen and then some.

Here the scripts.

Code:
#==============================================================================

# ** Window_Item

#------------------------------------------------------------------------------

#  This window displays items in possession on the item and battle screens.

#==============================================================================

 

class Window_Item

  attr_reader   :pic_window              # pic window

  alias pic_window_init initialize

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(0, 64, 478, 416)

    @column_max = 2

    refresh

    self.index = 0

    # If in battle, move window to center of screen

    # and make it semi-transparent

    if $game_temp.in_battle

      self.y = 64

      self.height = 256

      self.back_opacity = 160

    end

  end

  #--------------------------------------------------------------------------

  # * Draw Item

  #     index : item number

  #--------------------------------------------------------------------------

  def draw_item(index)

    item = @data[index]

    case item

    when RPG::Item

      number = $game_party.item_number(item.id)

    when RPG::Weapon

      number = $game_party.weapon_number(item.id)

    when RPG::Armor

      number = $game_party.armor_number(item.id)

    end

    if item.is_a?(RPG::Item) and

       $game_party.item_can_use?(item.id)

      self.contents.font.color = normal_color

    else

      self.contents.font.color = disabled_color

    end

    x = 4 + index % 2 * (207 + 32)

    y = index / 2 * 32

    rect = Rect.new(x - 4, y, self.width / @column_max - 32, 32)

    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))

    bitmap = RPG::Cache.icon(item.icon_name)

    opacity = self.contents.font.color == normal_color ? 255 : 128

    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)

    self.contents.draw_text(x + 28, y, 135, 32, item.name, 0)

    self.contents.draw_text(x + 165, y, 5, 32, ":", 0)

    self.contents.draw_text(x + 170, y, 24, 32, number.to_s, 2)

  end

  #--------------------------------------------------------------------------

  # * Picture Window Update

  #--------------------------------------------------------------------------

  def update_pic

    if self.item != nil

      @pic_window.refresh(self.item)

    end

  end

  #--------------------------------------------------------------------------

  # * Set pic Window

  #     help_window : new help window

  #--------------------------------------------------------------------------

  def pic_window=(pic_window)

    @pic_window = pic_window

    # Update help text (update_help is defined by the subclasses)

    if self.active and @pic_window != nil

      update_pic

    end

  end

  alias pic_window_update update

  def update

    pic_window_update

    update_pic

  end

end

Code:
#==============================================================================

# ** Window_Item_Right

#------------------------------------------------------------------------------

#  This window displays a picture of the currently selected item.

#  Requires an additional file for each item in the Icons folder.

#  File name is the same as the item icon, with "_lg" appended.

#  e.g.  001-Weapon01_lg.png  (Max size: 130 x 180)

#==============================================================================

 

class Window_Item_Right < Window_Base

  #--------------------------------------------------------------------------

  # * Object Initialization

  #--------------------------------------------------------------------------

  def initialize

    super(478, 64, 162, 416)

    # If in battle, move window to center of screen

    # and make it semi-transparent

    if $game_temp.in_battle

      self.y = 64

      self.height = 256

      self.back_opacity = 160

    end

  end

  #--------------------------------------------------------------------------

  # * Refresh

  #--------------------------------------------------------------------------

  def refresh(item)

    if self.contents != nil

      self.contents.dispose

      self.contents = nil

    end

    self.contents = Bitmap.new(130, 180)

    draw_item(item)

  end

  #--------------------------------------------------------------------------

  # * Draw Item

  #     index : item number

  #--------------------------------------------------------------------------

  def draw_item(item)

    name = item.icon_name + "_lg"

    if FileTest.exist?("Graphics\\Icons\\" + name + ".png")

      bitmap = RPG::Cache.icon(name)

    else

      bitmap = Bitmap.new(130, 180)

    end

    x = 65 - (bitmap.width / 2)

    y = 90 - (bitmap.height / 2)

    rect = Rect.new(0, 0, bitmap.width, bitmap.height)

    self.contents.blt(x, y, bitmap, rect, 255)

  end

end

Code:
class Scene_Item

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Make help window, item window

    @help_window = Window_Help.new

    @item_window = Window_Item.new

    @pic_window = Window_Item_Right.new   #BREW

    # Associate help window

    @item_window.help_window = @help_window

    @item_window.pic_window = @pic_window   #BREW

    # Make target window (set to invisible / inactive)

    @target_window = Window_Target.new

    @target_window.visible = false

    @target_window.active = false

    # Execute transition

    Graphics.transition

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @help_window.dispose

    @pic_window.dispose     #BREW

    @item_window.dispose

    @target_window.dispose

  end

end

Code:
class Scene_Battle

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Initialize each kind of temporary battle data

    $game_temp.in_battle = true

    $game_temp.battle_turn = 0

    $game_temp.battle_event_flags.clear

    $game_temp.battle_abort = false

    $game_temp.battle_main_phase = false

    $game_temp.battleback_name = $game_map.battleback_name

    $game_temp.forcing_battler = nil

    # Initialize battle event interpreter

    $game_system.battle_interpreter.setup(nil, 0)

    # Prepare troop

    @troop_id = $game_temp.battle_troop_id

    $game_troop.setup(@troop_id)

    # Make actor command window

    s1 = $data_system.words.attack

    s2 = $data_system.words.skill

    s3 = $data_system.words.guard

    s4 = $data_system.words.item

    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])

    @actor_command_window.y = 160

    @actor_command_window.back_opacity = 160

    @actor_command_window.active = false

    @actor_command_window.visible = false

    # Make other windows

    @party_command_window = Window_PartyCommand.new

    @help_window = Window_Help.new

    @help_window.back_opacity = 160

    @help_window.visible = false

    @status_window = Window_BattleStatus.new

    @message_window = Window_Message.new

    # Make sprite set

    @spriteset = Spriteset_Battle.new

    # Initialize wait count

    @wait_count = 0

    # Execute transition

    if $data_system.battle_transition == ""

      Graphics.transition(20)

    else

      Graphics.transition(40, "Graphics/Transitions/" +

        $data_system.battle_transition)

    end

    # Start pre-battle phase

    start_phase1

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Refresh map

    $game_map.refresh

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @actor_command_window.dispose

    @party_command_window.dispose

    @help_window.dispose

    @status_window.dispose

    @message_window.dispose

    if @skill_window != nil

      @skill_window.dispose

    end

    if @item_window != nil

      @item_window.dispose

    end

    if @pic_window != nil

      @pic_window.dispose

    end

    if @result_window != nil

      @result_window.dispose

    end

    # Dispose of sprite set

    @spriteset.dispose

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

    # If switching from battle test to any screen other than game over screen

    if $BTEST and not $scene.is_a?(Scene_Gameover)

      $scene = nil

    end

  end

  #--------------------------------------------------------------------------

  # * Start Item Selection

  #--------------------------------------------------------------------------

  def start_item_select

    # Make item window

    @item_window = Window_Item.new

    @pic_window = Window_Item_Right.new

    # Associate help window

    @item_window.help_window = @help_window

    @item_window.pic_window = @pic_window

    # Disable actor command window

    @actor_command_window.active = false

    @actor_command_window.visible = false

  end

end

I been wondering if anyone can help me fix this script. Thanks.
 
Replace Scene_Battle (the custom version) with:

Code:
class Scene_Battle

  #--------------------------------------------------------------------------

  # * Main Processing

  #--------------------------------------------------------------------------

  def main

    # Initialize each kind of temporary battle data

    $game_temp.in_battle = true

    $game_temp.battle_turn = 0

    $game_temp.battle_event_flags.clear

    $game_temp.battle_abort = false

    $game_temp.battle_main_phase = false

    $game_temp.battleback_name = $game_map.battleback_name

    $game_temp.forcing_battler = nil

    # Initialize battle event interpreter

    $game_system.battle_interpreter.setup(nil, 0)

    # Prepare troop

    @troop_id = $game_temp.battle_troop_id

    $game_troop.setup(@troop_id)

    # Make actor command window

    s1 = $data_system.words.attack

    s2 = $data_system.words.skill

    s3 = $data_system.words.guard

    s4 = $data_system.words.item

    @actor_command_window = Window_Command.new(160, [s1, s2, s3, s4])

    @actor_command_window.y = 160

    @actor_command_window.back_opacity = 160

    @actor_command_window.active = false

    @actor_command_window.visible = false

    # Make other windows

    @party_command_window = Window_PartyCommand.new

    @help_window = Window_Help.new

    @help_window.back_opacity = 160

    @help_window.visible = false

    @status_window = Window_BattleStatus.new

    @message_window = Window_Message.new

    # Make sprite set

    @spriteset = Spriteset_Battle.new

    # Initialize wait count

    @wait_count = 0

    # Execute transition

    if $data_system.battle_transition == ""

      Graphics.transition(20)

    else

      Graphics.transition(40, "Graphics/Transitions/" +

        $data_system.battle_transition)

    end

    # Start pre-battle phase

    start_phase1

    # Main loop

    loop do

      # Update game screen

      Graphics.update

      # Update input information

      Input.update

      # Frame update

      update

      # Abort loop if screen is changed

      if $scene != self

        break

      end

    end

    # Refresh map

    $game_map.refresh

    # Prepare for transition

    Graphics.freeze

    # Dispose of windows

    @actor_command_window.dispose

    @party_command_window.dispose

    @help_window.dispose

    @status_window.dispose

    @message_window.dispose

    if @skill_window != nil

      @skill_window.dispose

    end

    if @item_window != nil

      @item_window.dispose

    end

    if @pic_window != nil

      @pic_window.dispose

    end

    if @result_window != nil

      @result_window.dispose

    end

    # Dispose of sprite set

    @spriteset.dispose

    # If switching to title screen

    if $scene.is_a?(Scene_Title)

      # Fade out screen

      Graphics.transition

      Graphics.freeze

    end

    # If switching from battle test to any screen other than game over screen

    if $BTEST and not $scene.is_a?(Scene_Gameover)

      $scene = nil

    end

  end

  #--------------------------------------------------------------------------

  # * Start Item Selection

  #--------------------------------------------------------------------------

  def start_item_select

    # Make item window

    @item_window = Window_Item.new

    @pic_window = Window_Item_Right.new

    # Associate help window

    @item_window.help_window = @help_window

    @item_window.pic_window = @pic_window

    # Disable actor command window

    @actor_command_window.active = false

    @actor_command_window.visible = false

  end

  #--------------------------------------------------------------------------

  # * End Item Selection

  #--------------------------------------------------------------------------

  def end_item_select

    # Dispose of item window

    @item_window.dispose

    @item_window = nil

    @pic_window.dispose

    @pic_window = nil

    # Hide help window

    @help_window.visible = false

    # Enable actor command window

    @actor_command_window.active = true

    @actor_command_window.visible = true

  end

end
 

VCA

Member

Thank you Brewmeister. Thank you for fixing it and helping me too! You made this script even more awesome! P.S Do you know how to add or subtract variables by script, what i mean is a "call script" line.
 
If you mean game variables (the variables used in events), they are referenced with $game_variables[n]
So to add 5 to variable 1, it would be...

$game_variables[1] += 5

which is the same as

$game_variables[1] = $game_variables[1] + 5
 

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