Basically, what I'm trying to do is get the window for battle results (EXP earned, Gold earned, and Treasure) to only display if there's anything to display. I've eliminated EXP entirely (as this is a part of a Level/EXP Eliminator script for my Ability Grid that I'm editing), so I only need to worry about gold and treasure. The obvious method (to me) to do this is to use conditional branches, which you'll see at lines 18 and 31.
[rgss]#==============================================================================
# ** Window_BattleResult
#------------------------------------------------------------------------------
# This window displays amount of gold and EXP acquired at the end of a battle.
#==============================================================================
class Window_BattleResult < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# exp : EXP
# gold : amount of gold
# treasures : treasures
#--------------------------------------------------------------------------
def initialize(exp, gold, treasures)
@exp = exp
@gold = gold
@treasures = treasures
if @gold > 0 or @treasures.size > 0
super(240, 0, 160, @treasures.size * 32 + 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.y = 160 - height / 2
self.back_opacity = 160
self.visible = false
refresh
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if @gold > 0 or @treasures.size > 0
self.contents.clear
x = 4
self.contents.font.color = normal_color
cx = contents.text_size(@gold.to_s).width
self.contents.draw_text(x, 0, cx, 32, @gold.to_s)
x += cx + 4
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
y = 32
for item in @treasures
draw_item_name(item, 4, y)
y += 32
end
end
end
end
[/rgss]
I'm thinking about adding another conditional (so it'll only show treasures if no coins are gained), but at the moment I've hit a snag. But it's not with that piece of script, which appears to work as I wanted it to.
That is line 19 here:
[rgss]#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Frame Update (after battle phase)
#--------------------------------------------------------------------------
def update_phase5
# If wait count is larger than 0
if @phase5_wait_count > 0
# Decrease wait count
@phase5_wait_count -= 1
# If wait count reaches 0
if @phase5_wait_count == 0
# Show result window
@result_window.visible = true
# Clear main phase flag
$game_temp.battle_main_phase = false
# Refresh status window
@status_window.refresh
end
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Battle ends
battle_end(0)
end
end
end
[/rgss]
I'm assuming I'd just need to throw in a conditional branch there, but the problem is that I'm not sure what to reference because @gold and @treasures.size aren't defined in this class. I've tried a few things, but I always end up creating different errors, so I thought I'd ask someone who knows what they're doing.
If you can explain how to do this, it would be very much appreciated. I'm trying to learn RGSS at least a little, so I'd rather have an explanation than just be handed a script. :P
[rgss]#==============================================================================
# ** Window_BattleResult
#------------------------------------------------------------------------------
# This window displays amount of gold and EXP acquired at the end of a battle.
#==============================================================================
class Window_BattleResult < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
# exp : EXP
# gold : amount of gold
# treasures : treasures
#--------------------------------------------------------------------------
def initialize(exp, gold, treasures)
@exp = exp
@gold = gold
@treasures = treasures
if @gold > 0 or @treasures.size > 0
super(240, 0, 160, @treasures.size * 32 + 64)
self.contents = Bitmap.new(width - 32, height - 32)
self.y = 160 - height / 2
self.back_opacity = 160
self.visible = false
refresh
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
if @gold > 0 or @treasures.size > 0
self.contents.clear
x = 4
self.contents.font.color = normal_color
cx = contents.text_size(@gold.to_s).width
self.contents.draw_text(x, 0, cx, 32, @gold.to_s)
x += cx + 4
self.contents.font.color = system_color
self.contents.draw_text(x, 0, 128, 32, $data_system.words.gold)
y = 32
for item in @treasures
draw_item_name(item, 4, y)
y += 32
end
end
end
end
[/rgss]
I'm thinking about adding another conditional (so it'll only show treasures if no coins are gained), but at the moment I've hit a snag. But it's not with that piece of script, which appears to work as I wanted it to.
That is line 19 here:
[rgss]#==============================================================================
# ** Scene_Battle (part 2)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Frame Update (after battle phase)
#--------------------------------------------------------------------------
def update_phase5
# If wait count is larger than 0
if @phase5_wait_count > 0
# Decrease wait count
@phase5_wait_count -= 1
# If wait count reaches 0
if @phase5_wait_count == 0
# Show result window
@result_window.visible = true
# Clear main phase flag
$game_temp.battle_main_phase = false
# Refresh status window
@status_window.refresh
end
return
end
# If C button was pressed
if Input.trigger?(Input::C)
# Battle ends
battle_end(0)
end
end
end
[/rgss]
I'm assuming I'd just need to throw in a conditional branch there, but the problem is that I'm not sure what to reference because @gold and @treasures.size aren't defined in this class. I've tried a few things, but I always end up creating different errors, so I thought I'd ask someone who knows what they're doing.
If you can explain how to do this, it would be very much appreciated. I'm trying to learn RGSS at least a little, so I'd rather have an explanation than just be handed a script. :P