Heyo!
Intro and Context
For my next step in Ruby learning: I've been going line by line through previously made (public) scripts and making notes on what I believe each individual line does.
I'm doing this in the hopes that I'll be able to learn more about the parts of RGSS3 that I would like to edit for my own scripts.
So far it's going pretty well.
But I have encountered something I'm not sure how to read and thus figured I'd leave a question about it here:
The Problem / Situation
In Yanfly's Battle Engine Ace script, s/he makes it so the Window_BattleStatus class draws the faces of the Actors, it's pretty neat.
I believe I understand how most of this is done... but when it comes to the equations Yanfly has written for their local fx/fy/fw variables... I'm at a little bit of a loss.
Here is the code (I have left my comments in on the particular lines that are giving me trouble, just so you know where the parts that are confusing me are at):
Outro / Conclusion / The Questions
So there are two things that are tripping me up here:
The first is my lack of decent Maths skills. XD
1) How do I read the fx, fy and fw equations?
In my mind it goes:
fx is equal to 96 minus whatever item_rect.width plus 1 is, then divided by 2 and now why is there a 0 there and why is there also a 0 in brackets after item_rect but before width like whaaaaaaaaat?
fy is equal to face_index divided by 4 then multiplied by 96 and THEN 2 is added onto the end of it.
fw is equal to item_rect.width minus 4 but now why is there a 92 after it and why is there a 0 in brackets after item_rect but before .width again whaaaaaat iiiiis thiiiiis?
So as I'm sure you can see, I'm either horribly wrong about all that... or only slightly wrong and need to learn more about how equations work within arrays.
The second thing tripping me up is:
2) Why are there two "rect =" right on top of eachother? Doesn't the second "rect =" just immediately overwrite the first one?
I've tried commenting out the first one and it doesn't seem to make a difference at all as far as I can tell, whereas when I comment out the second one it mucks up what Actor faces are drawn (because the second "rect = " helps Ruby realise what Bitmap face is equal to what Actor).
So is that first "rect =" just a bit of accidental leftover code by Yanfly?
Or am I missing something about it due to my lack of complete knowledge of Ruby?
And that's that!
Thanks for any answers to my questions, sorry for having a not-great Maths education and for my (current) lack of super-knowledge when it comes to coding and Ruby.
Any help here is appreciated 🙂.
Intro and Context
For my next step in Ruby learning: I've been going line by line through previously made (public) scripts and making notes on what I believe each individual line does.
I'm doing this in the hopes that I'll be able to learn more about the parts of RGSS3 that I would like to edit for my own scripts.
So far it's going pretty well.
But I have encountered something I'm not sure how to read and thus figured I'd leave a question about it here:
The Problem / Situation
In Yanfly's Battle Engine Ace script, s/he makes it so the Window_BattleStatus class draws the faces of the Actors, it's pretty neat.
I believe I understand how most of this is done... but when it comes to the equations Yanfly has written for their local fx/fy/fw variables... I'm at a little bit of a loss.
Here is the code (I have left my comments in on the particular lines that are giving me trouble, just so you know where the parts that are confusing me are at):
Ruby:
#--------------------------------------------------------------------------
# overwrite method: draw_face
#--------------------------------------------------------------------------
def draw_face(face_name, face_index, dx, dy, enabled = true)
bitmap = Cache.face(face_name)
fx = [(96 - item_rect(0).width + 1) / 2, 0].max
# local fx variable = something I'll have to ask about
fy = face_index / 4 * 96 + 2
# local fy variable = other fancy stuff
fw = [item_rect(0).width - 4, 92].min
# local fw variable = other fancy stuff
rect = Rect.new(fx, fy, fw, 92)
# draws ??? rect as: x, y, width, height
rect = Rect.new(face_index % 4 * 96 + fx, fy, fw, 92)
# draws bitmap rect as: x, y, width, height (getting the correct Actor faces)
contents.blt(dx, dy, bitmap, rect, enabled ? 255 : translucent_alpha)
bitmap.dispose
end
Outro / Conclusion / The Questions
So there are two things that are tripping me up here:
The first is my lack of decent Maths skills. XD
1) How do I read the fx, fy and fw equations?
In my mind it goes:
Ruby:
fx = [(96 - item_rect(0).width + 1) / 2, 0].max
Ruby:
fy = face_index / 4 * 96 + 2
Ruby:
fw = [item_rect(0).width - 4, 92].min
So as I'm sure you can see, I'm either horribly wrong about all that... or only slightly wrong and need to learn more about how equations work within arrays.
The second thing tripping me up is:
2) Why are there two "rect =" right on top of eachother? Doesn't the second "rect =" just immediately overwrite the first one?
Ruby:
rect = Rect.new(fx, fy, fw, 92)
rect = Rect.new(face_index % 4 * 96 + fx, fy, fw, 92)
So is that first "rect =" just a bit of accidental leftover code by Yanfly?
Or am I missing something about it due to my lack of complete knowledge of Ruby?
And that's that!
Thanks for any answers to my questions, sorry for having a not-great Maths education and for my (current) lack of super-knowledge when it comes to coding and Ruby.
Any help here is appreciated 🙂.