A Rect is basically a section of the screen or a window that you're setting aside for something. It is literally just a theoretical rectangle which takes four parameters: top left X coordinate, top left Y coordinate, width, and height. For example, if I make a custom window and want to show a 16x16 picture at the bottom right of it, my rect for the bitmap would be (window.width - 16, window.height - 16, 16, 16). item_rect is a built-in method of Window_Selectable which calculates where the rect would need to be for showing a selectable option at the given index; that's how your menus and show choice boxes etc. know where to put each option.
Slip into Ruby: An introductory guide to RGSS for beginners.
Learning Ruby and RGSSxAnd today's dumb problem. I'm doing chapter One, Part 3 and everything was fine until I got to the section dealing with centring the enemy graphic. I input the code and when I go to playtest I get the error message
line 80: SyntaxError occurred
unexpect tLPAREN, expecting ')'
(bmp.rect.height - dest_rect.h...
The thing is, I have double, triple and quadruple checked my brackets and cannot see what is wrong. Here is what I have:
def setup_battler_graphic(x, y) bmp = setup_battler_graphic(x, y) rect = Rect.new(x, y, contents_width, contents_height) dest_rect, fits = battler_rect(bmp, rect) dummy_bmp = Bitmap.new(contents_width, contents_height) if fits dummy_bmp.blt(dest_rect.x, dest_rect.y, bmp, bmp_rect) else src_rect = Rect.new((bmp.rect.width - dest_rect.width) / 2 (bmp.rect.height - dest_rect.height) / 2, dest_rect.width, dest_rect.height) dummy_bmp.blt(dest_rect.x, dest_rect.y, bmp, src_rect) end dummy_bmp endI assume I need to take into account the previous line and its brackets as well. It opens with a double bracket. The first bracket is closed off after dest_rect.width. A new set of brackets is opened on line 80 with bmp.rect and is closed after dest_rect.height. The original double bracket is closed at the end of the whole line after dest_rect.height.
I simply don't see any other brackets which are still open and need to be closed on line 80.
line 80: SyntaxError occurred
unexpect tLPAREN, expecting ')'
(bmp.rect.height - dest_rect.h...
The thing is, I have double, triple and quadruple checked my brackets and cannot see what is wrong. Here is what I have:
def setup_battler_graphic(x, y) bmp = setup_battler_graphic(x, y) rect = Rect.new(x, y, contents_width, contents_height) dest_rect, fits = battler_rect(bmp, rect) dummy_bmp = Bitmap.new(contents_width, contents_height) if fits dummy_bmp.blt(dest_rect.x, dest_rect.y, bmp, bmp_rect) else src_rect = Rect.new((bmp.rect.width - dest_rect.width) / 2 (bmp.rect.height - dest_rect.height) / 2, dest_rect.width, dest_rect.height) dummy_bmp.blt(dest_rect.x, dest_rect.y, bmp, src_rect) end dummy_bmp endI assume I need to take into account the previous line and its brackets as well. It opens with a double bracket. The first bracket is closed off after dest_rect.width. A new set of brackets is opened on line 80 with bmp.rect and is closed after dest_rect.height. The original double bracket is closed at the end of the whole line after dest_rect.height.
I simply don't see any other brackets which are still open and need to be closed on line 80.
It seems you are missing a comma ',' after the first line of the Rect.
What lavra said; you're missing the comma after "/ 2".
hangs head in shame, and crawls off into a corner, covered with embarrassment.
Thanks.
Thanks.
Hey, don't be embarrassed: I've lost count of the number of times I've spent ages trawling through code looking for bugs only to realise I missed a semicolon or something (Java, I hate you)
Uh, but you can (and should) use Eclipse for Java, which does a lot to prevent errors. I wish the Ace script editor would have better functionality...or at least full screen.
I write most of my Java in Netbeans, but I was referring more to code I wrote back before IDEs had great error checking.
Thanks! That helps a lot. I'm hoping, after going through a bunch of your tutorials, I'll be able to start experimenting with code to see what I can do, as I find trying things, and figuring out what works and what doesn't will help quite a bit.
That's how I learned when I was starting out with programming. You can't figure out what something does if you don't poke at it until it breaks and then try to fix it! 😀
I just read the tutorial on the modules (part 1 anyway), and it was extraordinarly helpful. It cleared up a few of my questions. I don't understand all the Ruby syntax (which is something I hope I'll understand better as I go through these, in combination with the help files), but I understood, generally speaking, what most of the stuff did in the ones you covered. So thank you! I found it really helpful.
Just something you might want to make a bit more explicit, as this is aimed at total beginners.
In Chapter One, Part 3, you have this:
To see the results of our handiwork, add the following lines underneath the ones in Scene_Bestiary pertaining to @list_window:
@battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.width - 300)@battler_window.viewport = @viewport
And that is literally what I did. I put those 2 lines directly under what was already there. It works. By the end of part 3 the enemy battler graphic was nicely centred etc.
However, at the beginning of Part 4, you give the full code so far. I checked what you had against what I had, just to be on the safe side, and saw that those 2 lines were now
def create_battler_window @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.height - 175) @battler_window.viewport = @viewport endYou hadn't actually said to put them into their own definition. Perhaps it should have been obviously to me that this is what needed to be done, but being such a beginner, it wasn't. I followed the instructions literally and just put them under the @list_window
In addition, there was an extra line under @list_window:
create_battler_window
Nowhere in Part 3 does it say to write that line, at least as far as my eyes and CtrlF could discover.
Following exactly what Part 3 says, this is what I have and it works.
class Scene_Bestiary < Scene_MenuBase def start super @list_window = Window_EnemyList.new(0, 0, 200) @list_window.set_handler🙂cancel, method🙂return_scene)) @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.width - 300) @battler_window.viewport = @viewport endendBut at the beginning of Part 4 it says I should have
class Scene_Bestiary < Scene_MenuBase def start super @list_window = Window_EnemyList.new(0, 0, 200) create_battler_window @list_window.set_handler🙂cancel, method🙂return_scene)) end def create_battler_window @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.height - 175) @battler_window.viewport = @viewport endendI am now even more confused than ever. As it works with my original version, why do I need the extra line and putting the 2 lines into their own definition?
In Chapter One, Part 3, you have this:
To see the results of our handiwork, add the following lines underneath the ones in Scene_Bestiary pertaining to @list_window:
@battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.width - 300)@battler_window.viewport = @viewport
And that is literally what I did. I put those 2 lines directly under what was already there. It works. By the end of part 3 the enemy battler graphic was nicely centred etc.
However, at the beginning of Part 4, you give the full code so far. I checked what you had against what I had, just to be on the safe side, and saw that those 2 lines were now
def create_battler_window @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.height - 175) @battler_window.viewport = @viewport endYou hadn't actually said to put them into their own definition. Perhaps it should have been obviously to me that this is what needed to be done, but being such a beginner, it wasn't. I followed the instructions literally and just put them under the @list_window
In addition, there was an extra line under @list_window:
create_battler_window
Nowhere in Part 3 does it say to write that line, at least as far as my eyes and CtrlF could discover.
Following exactly what Part 3 says, this is what I have and it works.
class Scene_Bestiary < Scene_MenuBase def start super @list_window = Window_EnemyList.new(0, 0, 200) @list_window.set_handler🙂cancel, method🙂return_scene)) @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.width - 300) @battler_window.viewport = @viewport endendBut at the beginning of Part 4 it says I should have
class Scene_Bestiary < Scene_MenuBase def start super @list_window = Window_EnemyList.new(0, 0, 200) create_battler_window @list_window.set_handler🙂cancel, method🙂return_scene)) end def create_battler_window @battler_window = Window_EnemyBattler.new(@list_window, 200, 0, Graphics.width - 200, Graphics.height - 175) @battler_window.viewport = @viewport endendI am now even more confused than ever. As it works with my original version, why do I need the extra line and putting the 2 lines into their own definition?
That method isn't necessary, however you can use it if you want to be more methodical (ahah pun intended),
if you put those two lines in "def start" is the same thing than putting them in "def create_battler_window" and then calling it within "def start".
if you put those two lines in "def start" is the same thing than putting them in "def create_battler_window" and then calling it within "def start".
Whoops! That's a bit of a snafu on my part. I noticed when reviewing the series so far that I had made a mistake in the initialize for @battler_window (I used Graphics.width where it should have been Graphics.height) and while I was fixing that I decided to put the window creation into its own method to be more consistent with the other scenes, but I forgot to incorporate the changes into my instructions. Sorry!
Okay, just to make doubly, triply sure I am starting to figure this out...
If I write a script, chucked in at the bottom of the script list, where I bring in new definitions like, say, the extra actions mechanic.
Writing a new "def make_action_times" script will render the original script null and void, right?
If I write a script, chucked in at the bottom of the script list, where I bring in new definitions like, say, the extra actions mechanic.
Writing a new "def make_action_times" script will render the original script null and void, right?
I've started Chapter Two, and looking at the Vocab module reminded me of something that I've been meaning to ask.
This script, like many others, is littered with "%s" . What exactly is "%s"? I can sort of vaguely intuit what it means, but I don't think that's good enough for understanding scripts.
Thanks.
This script, like many others, is littered with "%s" . What exactly is "%s"? I can sort of vaguely intuit what it means, but I don't think that's good enough for understanding scripts.
Thanks.
"%s" is used in sprintf as a placeholder for a parameter, that is then converted into a string. Example:
p sprintf("a %s c", "b")This will print "a b c" to the console.
p sprintf("a %s c", "b")This will print "a b c" to the console.
What lavra said. I believe a later part does actually go into detail on sprintf.
Warpmind: Yes, that's known as overloading a method. Writing a method definition which has already been defined further up will replace the old method with your new one.
Warpmind: Yes, that's known as overloading a method. Writing a method definition which has already been defined further up will replace the old method with your new one.
Good; I understood correctly. :3
New one's up! This one just covers Game_Actor since it's so very, very long. The next one will probably be finished in the next couple of hours, as I started it shortly after I finished this one. http://rpgmaker.net/articles/1129/
Original thread: https://forums.rpgmakerweb.com/threads/slip-into-ruby-an-introductory-guide-to-rgss-for-beginners.38900/