i've been trying to fix up the hud for the XGrid for my game for a while, the part i'm trying to fix up now is setting up a hud which displays the player's stats, this is the script
# Xgrid Class (Chaos-Project Stripped)
class XGrid
attr_accessor :hud
# inialized values
def initialize
@hud = nil
end
end
class XGrid_Char < Sprite
SYSTEM_COLOR = Color.new(192, 224, 255)
NORMAL_COLOR = Color.new(255, 255, 255)
CLEAR = Color.new(0, 0, 0, 96)
VIEWPORT_Z = 10000
# Defines what types of info will be drawn
TIME = true
def initialize
viewport = Viewport.new(0, 0, 640, 480)
viewport.z = VIEWPORT_Z
super(viewport)
# Initialize the words used for each value.
self.bitmap = Bitmap.new(640, 480)
self.bitmap.font.name = 'Arial'
self.bitmap.font.size = 14
self.bitmap.font.bold = true
@refresh = [TIME]
@data = []
@data[0] = time_info if @refresh[0]
# Draw all the items.
@data.each_index {|i|
if @data[i] != nil
draw_items(Array.new(@data[i][0].size) {|j| j }, i)
end
}
# Self updating thread.
@thread = Thread.new { loop { $xgrid.hud.update if $xgrid.hud != nil } }
end
def dispose
# Terminate the update thread when the sprite is disposed.
@thread.kill
@thread = nil
super
end
def get_info(index)
return case index
when 0 then time_info
end
end
def update
# Check for change in values. Re-draws the lines that have changed.
@refresh.each_index {|i|
if @refresh[i]
info = get_info(i)
if @data[i][1] != info[1]
draw_items(get_indexes(@data[i][1], info[1]), i)
draw_items(get_indexes(@data[i][2], info[2]), i)
#draw_items(get_indexes(@data[i][3], info[3]), i)
#draw_items(get_indexes(@data[i][4], info[4]), i)
#draw_items(get_indexes(@data[i][5], info[5]), i)
@data[i] = info
end
end
}
# Dispose debugger and terminate thread if not Scene_Map
unless $scene.is_a?(Scene_Map)
$xgrid.hud.dispose
end
end
def draw_items(indexes, group)
array = case group
when 0 then [5, 5, 128]
#when 0 then [16, 304, 128]
#when 1 then [160, 424, 128]
#when 2 then [160+128, 424, 128]
#when 3 then [160, 424, 128]
#when 4 then [160, 424, 128]
#when 5 then [160, 424, 128]
else
[304+((group-2)*112), 412, 96]
end
self.bitmap.fill_rect(0, 0, 350, 95, CLEAR)
indexes.each {|index|
# Create a rect at the specific line.
rect = Rect.new(array[0], (index*12)+array[1], array[2], 12)
# Draw line number INDEX.
self.bitmap.font.color = SYSTEM_COLOR
self.bitmap.draw_text(rect, @data[group][0][index])
self.bitmap.font.color = NORMAL_COLOR
self.bitmap.draw_text(5, (index*12)+5, 100, 12, @data[group][1][index], 2)
# self.bitmap.draw_text(40, (index*12)+5, 128, 12, @data[group][2][index], 2)
# self.bitmap.draw_text(100, (index*12)+5, 128, 12, @data[group][3][index], 2)
# self.bitmap.draw_text(165, (index*12)+5, 128, 12, @data[group][4][index], 2)
# self.bitmap.draw_text(215, (index*12)+5, 128, 12, @data[group][5][index], 2)
}
end
def get_indexes(array1, array2)
indexes = []
array1.each_index {|i| indexes.push(i) if array1[i] != array2[i] }
return indexes
end
def time_info
# Return strings releated to the time.
return [
[' Character Stats', 'HP ', 'MP ', 'STR ', 'DEX ', 'AGI ', 'INT '],
['', $game_actors[1].maxhp.to_s, $game_actors[1].maxsp.to_s, $game_actors[1].str.to_s, $game_actors[1].dex.to_s, $game_actors[1].agi.to_s, $game_actors[1].int.to_s]
]
end
end
the purpose of the HUD is to show Actor 1's stats and update when it's changed so i have an event set up with this Call Script
but when i tigger the event RPG Maker XP shuts down and i don't get an error, if i trigger the second event to increase str it doesn't crash and the Actor's str stat increases
NOTE: yes, the XGrid_Char Class is just a copy of ForeverZer0's CCTS's debug script found in the demo of the script with some chnages to change where it's positioned and the content
EDIT: wow, the Orange Juice i am drinking must have drugs in it cause the code looks funky, i like it, too bad the preview when making tyhe post didn't do this