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 with draw bar section!

One of my script i use draws bars and displays numbers when changing party members. The only problem is, when a character reaches the final level (the highest level they can get to), the EXP bar turns into ---/--- and my script doesnt know what to do about that.
Heres the part of teh script im havin trouble with:

def draw_bar(x, y, min, max, width = 152, height = 20)
self.contents.fill_rect(x, y, width, height, Color.new(255, 255, 255, 100))
bar_color = Color.new(0, 0, 200, 255)
for i in 0..(width * min / max)
r = bar_color.red * (width - i) / width + 0 * i / width
g = bar_color.green * (width - i) / width + 0 * i / width
b = bar_color.blue * (width - i) / width + 0 * i / width
a = bar_color.alpha * (width - i) / width + 255 * i / width
self.contents.fill_rect(x + i, y, 1 , height, Color.new(r, g, b, a))
end
end


EDIT: Also, theres a draw information area that i didnt notice XD
Here it is

#--------------------------------------------------------------------------
# Draws Information
#--------------------------------------------------------------------------
def draw_info
contents.clear
# Draws actors
for i in 0...@actors.size
actor = @actors
y = i * 64 + 8
if actor == nil
contents.font.size = 40
contents.font.color = disabled_color
contents.draw_text(60, y - 8, contents.width, 64, "Empty Position")
else
contents.font.size = 22
# Draws Name
contents.font.color = normal_color
contents.draw_text(60, y, 90, 24, actor.name)
# Draws Class
contents.draw_text(60, y + 24, 90, 24, $data_classes[actor.class_id].name)
# Draws Level
contents.font.color = system_color
contents.draw_text(160, y, 100, 24, "Level")
contents.font.color = normal_color
contents.draw_text(160, y, 100, 24, actor.level.to_s, 2)
# Draws State
state = make_battler_state_text(actor, 112, true)
contents.font.color = actor.hp == 0 ? knockout_color : normal_color
contents.draw_text(160, y + 24, 100, 24, state)
# Draws Experience
contents.font.color = system_color
contents.draw_text(274, y, 160, 24, "Exp")
contents.font.color = normal_color
contents.draw_text(274, y, 160, 24, actor.exp.to_s, 2)
# Draws Next Level Bar
draw_bar(270, y + 26, actor.exp, actor.next_exp_s.to_i, 168)
# Draws Next Level
contents.font.color = system_color
contents.draw_text(274, y + 24, 160, 24, "Next Level")
contents.font.color = normal_color
contents.draw_text(274, y + 24, 160, 24, actor.next_rest_exp_s.to_s, 2)
# Draw HP Bar
draw_bar(446, y + 2, actor.hp, actor.maxhp)
# Draw MP Bar
draw_bar(446, y + 26, actor.sp, actor.maxsp)
# Draws HP
contents.font.size = 22
contents.font.color = system_color
contents.draw_text(452, y, 160, 24, $data_system.words.hp)
contents.font.size = 16
contents.font.color = actor.hp == 0 ? knockout_color : normal_color
contents.draw_text(452, y, 140, 24, "#{actor.hp} / #{actor.maxhp}", 2)
# Draws SP
contents.font.size = 22
contents.font.color = system_color
contents.draw_text(452, y + 24, 160, 24, $data_system.words.sp)
contents.font.size = 16
contents.font.color = actor.sp == 0 ? knockout_color : normal_color
contents.draw_text(452, y + 24, 140, 24, "#{actor.sp} / #{actor.maxsp}", 2)
end
end
end


could someone edit this as to when a character reaches max level, the bar will stay at 100%?
thx for the help! :)
 
That should fix your problem:

Code:
#--------------------------------------------------------------------------
# Draws Information
#--------------------------------------------------------------------------
def draw_info
contents.clear
# Draws actors
for i in 0...@actors.size
actor = @actors[i]
y = i * 64 + 8
if actor == nil
contents.font.size = 40
contents.font.color = disabled_color
contents.draw_text(60, y - 8, contents.width, 64, "Empty Position")
else
contents.font.size = 22
# Draws Name
contents.font.color = normal_color
contents.draw_text(60, y, 90, 24, actor.name)
# Draws Class
contents.draw_text(60, y + 24, 90, 24, $data_classes[actor.class_id].name)
# Draws Level
contents.font.color = system_color
contents.draw_text(160, y, 100, 24, "Level")
contents.font.color = normal_color
contents.draw_text(160, y, 100, 24, actor.level.to_s, 2)
# Draws State
state = make_battler_state_text(actor, 112, true)
contents.font.color = actor.hp == 0 ? knockout_color : normal_color
contents.draw_text(160, y + 24, 100, 24, state)
# Draws Experience
contents.font.color = system_color
contents.draw_text(274, y, 160, 24, "Exp")
contents.font.color = normal_color
contents.draw_text(274, y, 160, 24, actor.exp.to_s, 2)
# Draws Next Level Bar
@now_exp = actor.level == 99 ? 1 : actor.exp
@next_exp = actor.level == 99 ? 1 :actor.next_exp_s.to_i
draw_bar(270, y + 26, @now_exp, @next_exp, 168)
# Draws Next Level
contents.font.color = system_color
contents.draw_text(274, y + 24, 160, 24, "Next Level")
contents.font.color = normal_color
contents.draw_text(274, y + 24, 160, 24, actor.next_rest_exp_s.to_s, 2)
# Draw HP Bar
draw_bar(446, y + 2, actor.hp, actor.maxhp)
# Draw MP Bar
draw_bar(446, y + 26, actor.sp, actor.maxsp)
# Draws HP
contents.font.size = 22
contents.font.color = system_color
contents.draw_text(452, y, 160, 24, $data_system.words.hp)
contents.font.size = 16
contents.font.color = actor.hp == 0 ? knockout_color : normal_color
contents.draw_text(452, y, 140, 24, "#{actor.hp} / #{actor.maxhp}", 2)
# Draws SP
contents.font.size = 22
contents.font.color = system_color
contents.draw_text(452, y + 24, 160, 24, $data_system.words.sp)
contents.font.size = 16
contents.font.color = actor.sp == 0 ? knockout_color : normal_color
contents.draw_text(452, y + 24, 140, 24, "#{actor.sp} / #{actor.maxsp}", 2)
end
end
end
 
hmmm im still getting the error:
Script Data Line 155: ZeroDivsionError occurred
divided by 0

line 155 reads:
for i in 0..(width * min / max)
(its in the first section of script i put up)

maybe if i could change the ---/--- to the actual number of exp i have out of the same number...

EDIT: OK thx for your help! I finally got it! =D
 

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