I'm having trouble with my MiniHud... Hopefully, someone can help. :^_^':
class HudGunMini < Sprite
def initialize(viewport = nil)
super
self.x, self.y, self.z, self.opacity = 50, 120, 5000, 255
self.bitmap = Bitmap.new(150, 43)
refresh
end
def refresh
self.bitmap.fill_rect(1, 20, 120, 28, Color.new(0, 0, 0, 0))
@gunministring = $gunletterarray
string = []
if @gunministring != nil
for i in 0..@gunministring.size
case @gunministring[i]
when 1
string.push('A')
when 2
string.push('B')
when 3
string.push('C')
end
return string
end
end
self.bitmap.draw_text(1, 20, 120, 28, string.to_s, 1)
end
def update
refresh if @gunministring != $gunletterarray
end
end
class Scene_Map
alias upd_gunmini update
def update
$gunminihud.update if $gunminihud != nil
upd_gunmini
end
end
What I want this HUD to do is to show a certain key combination on the map.
The Key combination is stored within $gunletterarray as numbers like [1, 2, 3] would be A, B, C.
I am able to show the key combination in the form of numbers using
self.bitmap.draw_text(1, 20, 120, 28, $gunletterarray.to_s, 1)
The problem I'm having is converting the array such that 1 => A, 2 => B, etc.
if @gunministring != nil
for i in 0..@gunministring.size
case @gunministring[i]
when 1
string.push('A')
when 2
string.push('B')
when 3
string.push('C')
end
return string
end
end
From what I can tell... this should take the value of $gunletterarray at index i and throw it into the case.
So, if i is 1, then it should push 'A' into the string then repeat with the next index.
But when I display it using
self.bitmap.draw_text(1, 20, 120, 28, string.to_s, 1)
Nothing shows up at all... =/
No error message... just... emptiness...
Any suggestions?
The solution is very easy. Comment out the line that says "return string".
What's happening is that when it's told to return, it stops processing the function, so it never gets to the part where it actually draws anything on screen.
O.o I'm preeeetty sure I tried that right before I posted this, and it didn't work...
Now, for some reason... it works... XD
Thanks a lot, shdw :D
Lol I'll probably come back to this thread to ask more questions I have later...
Edit...
Here's the script so far.
class HudGunMini < Sprite
def initialize(viewport = nil)
super
self.x, self.y, self.z, self.opacity = 120, 120, 5000, 255
self.bitmap = Bitmap.new(500, 43)
refresh
end
def refresh
@gunministring = $gunletterarray
string = []
self.bitmap.fill_rect(1, 20, 640, 90, Color.new(0, 0, 0, 0))
self.bitmap.fill_rect(1, 20, 400, 28, Color.new(0, 0, 0, 80))
if @gunministring != nil
for i in 0..@gunministring.size
case @gunministring[i]
when 1
string.push('A')
when 2
string.push('B')
when 3
string.push('C')
end
end
end
@string = string
@tmp = $gunimputtedarray
for i in 0..string.size
if $guninputtedarray != nil
if $guninputtedarray[i] == string[i]
stringcolor = Color.new(100, 235, 20, 255)
else
stringcolor = Color.new(0, 255, 255, 255)
end
self.bitmap.font.color = stringcolor
self.bitmap.draw_text(20*i+3, 18, 400, 28, string[i].to_s, 0)
end
end
end
def update
refresh if @gunministring != $gunletterarray
refresh if @tmp != $guninputtedarray
end
end
class Scene_Map
alias upd_gunmini update
def update
$gunminihud.update if $gunminihud != nil
upd_gunmini
end
end
However, with this, I run into 2 bugs.
First, when the string gets too long, it runs off the black area.
(http://img4.imageshack.us/img4/7322/buggles.png)
Is there away to make the string break into a new line if its width is bigger than 390?
Second, I wanted the each letter to change color when it's pressed. What I did was this:
for i in 0..string.size
if $guninputtedarray != nil
if $guninputtedarray[i] == string[i]
stringcolor = Color.new(100, 235, 20, 255)
else
stringcolor = Color.new(0, 255, 255, 255)
end
self.bitmap.font.color = stringcolor
self.bitmap.draw_text(20*i+3, 18, 400, 28, string[i].to_s, 0)
end
I think it works... except the HUD doesn't update the change. I tried different conditions for the update method, but I can't seem to get it to work...
Fixed the second... Was using the @string instead of $gunletterarray XD
Aqua, some of my scripts have a method that takes the text and the max width as parameters and returns an array of the split text. It's called slice_text or something like that. Search the forum, you should find it quickly. I think that I used it in the AAS and in the Bestiary.
Mmm... I solved the overflow problem by making a new line every 20 letters... XD
But now... whenever it gets to around 40+ letters, it lags a LOT. At 100, it drops to 5 FPS... >.<
Can someone look at my code and see if I can make it less laggy?
class HudGunMini < Sprite
def initialize(viewport = nil)
super
self.x, self.y, self.z, self.opacity = 120, 120, 5000, 255
self.bitmap = Bitmap.new(500, 300)
refresh
end
def refresh
@gunministring = $gunletterarray
string = []
self.bitmap.fill_rect(1, 20, 400, 128, Color.new(0, 0, 0, 80))
if @gunministring != nil
for i in 0..@gunministring.size
case @gunministring[i]
when 1
string.push('A')
when 2
string.push('B')
when 3
string.push('C')
when 4
string.push('D')
when 5
string.push('E')
when 6
string.push('F')
when 7
string.push('G')
when 8
string.push('H')
when 9
string.push('I')
when 10
string.push('J')
when 11
string.push('K')
when 12
string.push('L')
when 13
string.push('M')
when 14
string.push('N')
when 15
string.push('O')
when 16
string.push('P')
when 17
string.push('Q')
when 18
string.push('R')
when 19
string.push('S')
when 20
string.push('T')
when 21
string.push('U')
when 22
string.push('V')
when 23
string.push('W')
when 24
string.push('X')
when 25
string.push('Y')
when 26
string.push('Z')
end
end
end
@string = string
@tmp = $gunimputtedarray
for i in 0..string.size
if $guninputtedarray != nil
if $guninputtedarray[i] == $gunletterarray[i]
stringcolor = Color.new(121, 188, 255, 255)
else
stringcolor = Color.new(255, 255, 255, 255)
end
self.bitmap.font.color = stringcolor
e = i % 20
h = i / 20
h += 1
self.bitmap.draw_text(19*e-180, 18*h, 400, 28, string[i].to_s, 1)
end
end
#self.bitmap.draw_text(1, 20, 400, 28, string.to_s, 1)
end
def update
refresh if @gunministring != $gunletterarray
refresh if @tmp != $guninputtedarray
end
end
class Scene_Map
alias upd_gunmini update
def update
$gunminihud.update if $gunminihud != nil
upd_gunmini
end
end