Fixing HUD display script

I am test playing a modification to a script I have that creates a help HUD for an ABS. The unmodded scripts works great, but the modded version I created (to add a HUD for MP as well) as soon as I click new game crashes and gives me RGSS3 player has stopped working. I will post my modded script here and see if you can get it working please. It is a simple script.

-----------------------------------------------------------------

Spoiler
module Cache
#--------------------------------------------------------------------------
# * Get Hud Graphic
#--------------------------------------------------------------------------
def self.hud(filename, hue=0)
load_bitmap("Graphics/System/Hud/", filename, hue)
end
end

class ZeldaHearts < Window_Base
#--------------------------------------------------------------------------
# * Changeable Area
#--------------------------------------------------------------------------
def switch
90
end

def heart_hud_x
0
end

def heart_hud_y
0
end

def magic_hud_x
30
end

def magic_hud_y
0
end

def hud_width
400
end

def hud_height
240
end

def heart_file
"hearts.png"
end

def magic_file
"magic.png"
end

def heart_width
24
end

def heart_padding
-10
end

def heart_rowheight
-10
end

def heart_row
10
end

def hp_per_heart
4
end

def mp_per_magic
4
end

def heart_pieces
4
end

def magic_pieces
4
end

#--------------------------------------------------------------------------
# * Fixed Area
#--------------------------------------------------------------------------
def initialize
super(heart_hud_x, heart_hud_y, hud_width, hud_height)
super(magic_hud_x, magic_hud_y, hud_width, hud_height)
self.windowskin = nil
@bitmap = Cache.hud(heart_file)
@switch = $game_switches[switch]
if @switch
draw_hearts
draw_magic
end
end

def draw_hearts
@lhearts = @hearts
@lmaxHearts = @maxHearts
@hearts = calc_hearts(get_hp)
@maxHearts = calc_hearts(get_maxhp).to_i

fullHearts = @hearts.to_i
partHearts = @hearts - fullHearts
i = 0
if fullHearts
for i in 0..@maxHearts-1 do 
if i < fullHearts
get_heart_image(i, heart_pieces)
elsif i == fullHearts
get_heart_image(i, (partHearts*heart_pieces).round(0)) 
else
get_heart_image(i,0)
end
end
end
end

def draw_magic
@lmagic = @magic
@lmaxMagic = @maxMagic
@magic = calc_magic(get_mp)
@maxMagic = calc_magic(get_maxmp).to_j

fullMagic = @magic.to_j
partMagic = @magic - fullMagic
j = 0
if fullMagic
for j in 0..@maxMagic-1 do 
if j < fullMagic
get_magic_image(j, magic_pieces)
elsif j == fullMagic
get_heart_image(j, (partMagic*magic_pieces).round(0)) 
else
get_magic_image(j,0)
end
end
end
end

def get_heart_image(heartIndex, fileIndex) 
rect = Rect.new(fileIndex * heart_width, 0, @bitmap.width/(heart_pieces+1), @bitmap.height)
contents.blt(heartIndex.modulo(heart_row)*(heart_width+heart_padding), (heartIndex/heart_row)*(@bitmap.height+heart_rowheight), @bitmap, rect, 255)
end

def get_magic_image(magicIndex, fileIndex) 
rect = Rect.new(fileIndex * heart_width, 0, @bitmap.width/(magic_pieces+1), @bitmap.height)
contents.blt(magicIndex.modulo(heart_row)*(heart_width+heart_padding), (magicIndex/heart_row)*(@bitmap.height+heart_rowheight), @bitmap, rect, 255)
end

def get_hp
$game_party.members[0].hp
end

def get_mp
$game_party.members[0].mp
end

def get_maxhp
$game_party.members[0].mhp
end

def get_maxmp
$game_party.members[0].mmp
end

def calc_hearts(hp)
Float hearts = hp.to_f / hp_per_heart
hearts.round(2)
end

def calc_magic(mp)
Float magic = mp.to_f / mp_per_magic
magic.round(2)
end

def refresh
self.contents.clear
contents.clear
draw_hearts
draw_magic
end
def update
super 
if @switch
refresh
end
end

def change 
if @switch != $game_switches[switch]
if $game_switches[switch]
update
else
contents.clear
self.contents.clear
end
@switch = $game_switches[switch]
end
if @lhearts == @hearts && @lmaxHearts == @maxHearts
return
else
update
end
if @lmagic == @magic && @lmaxMagic == @maxMagic
return
else
update
end
end

def dispose
super
@bitmap.dispose
end
end

class Scene_Map < Scene_Base
alias start_window start
alias term_window terminate
alias update_window update

def start
start_window
@hearthud = ZeldaHearts.new 
update
end

def terminate
@hearthud.dispose
term_window
end

def update
update_window
@hearthud.change 
end
end 
-----------------------------------------------------------------
Don't forget to put your code into code tags, it's really hard to read without them.
Use code tags around code, and for long scripts (which this is), enclose the whole lot in spoiler tags. You'll need to paste your script again when you do this, rather than just adding the tags, as the formatting has already been lost.


I don't know if this will make a difference, but change your file names (hearts.png, magic.png) to remove the extension. Extensions aren't used in the Cache module.
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/fixing-hud-display-script.18352/