by Enelvon
Introduction
This script is essentially a scripter's resource, but it has been optimized for use by those with little-to-no experience in scripting. It provides a parent class for multi-page windows, with a focus on those used to display information (though it is also possible, with some additions, to include pages with selectable areas). Its write_page_text method draws text in a similar manner to the draw_text_ex method, allowing you to use any control character that you would normally use in game text (with the exception of those that control timing). Further down, I have included a tutorial on creating a basic guide to a game's controls as an example of a simple use of the script. By reading the tutorial, a non-scripter can learn how to easily create and call a book window. I had a non-scripter friend try it out, and within ten minutes they had written a functional battle guide. Try it out and see what you can make!
Usage
In most cases, this is just going to be a superclass for other scripts. If you are interested in learning how to use it to make something yourself, refer to the tutorial in the spoiler below.
Spoiler
This script serves as a resource to create multi-page windows. I will use this space to give an example of how to make and display a simple book that contains the controls for the game.
The first thing that we have to do is create a new window class. Let's call it Guide.
class Guide < Window_BookOkay, so we've opened our class. Now we need to define our initialize method. It will contain our definition of @pagetext.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super endSorry about how long those text lines are, but going down to a new line and having indentations causes the formatting to be hideous when the text is drawn. Anyway, as you can see, we're able to use control characters from the game's message windows in our text. Always make sure to use two (rather than one) backslashes for the control character, and that it is attached to the first word/character that it is intended to affect. I skipped page 1 because we'll do that a little differently - we're going to center the text for it and place it near the top of the page, as it's the cover of the book.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super end def draw_page1 x = (contents_width - text_size("Game Guide").width) / 2 y = (contents_height - line_height) / 4 draw_text_ex(x, y, "\\c[14]Game Guide") endHere we find the center of the book page horizontally and 1/4 of the page vertically, then draw the text there. Now we have five pages in our book (four in the @pagetext hash and one defined explicitly), so the next thing we should do is define max_pages.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super end def draw_page1 x = (contents_width - text_size("Game Guide").width) / 2 y = (contents_height - line_height) / 4 draw_text_ex(x, y, "\\c[14]Game Guide") end def max_pages; 5; endendThere we go! As you can see, I ended the Guide class after defining max_pages. Why? Because it's done! We created a five-page book in 20 lines, and 7 of those were used to define the contents of the pages! Isn't that easy?
We're not quite done, though. We have one more task ahead of us: calling the window for display. Prior to version 1.3, this had to be done by creating a new class and calling that. 1.3 introduced the Scene_Book class, which simplified this for basic users - advanced books will still need their own classes if they're going to be used for anything but simple reading. To call the default book scene with the guide, put this in an event:
show_book(Guide, Scene_Map)That will display the book, as I've added the show_book command to the Game Interpreter class. You could also use this:
SceneManager.goto(Scene_Book)SceneManager.scene.set_book(Guide, Scene_Map)show_book is a little faster, though. You can replace Guide with the name of your book to show whatever you'd like - let's say we have a book window named Biology_Textbook. We would use this:
show_book(Biology_Textbook, Scene_Map)Note that show_book will return to the scene that you enter as its second parameter when the book is closed. It defaults to Scene_Map if no scene is given - I simply included Scene_Map in the examples to show that you can designate a scene.
That's it! Congratulations, you've created a guide! Your players will never have to puzzle over the controls again!
Anyway, I hope you can see how easy it is to use this as a base to make your own books. I can't wait to see what you come up with - make sure to let me know if you use it! Feel free to read over the rest of the script if you're learning to write code or are simply curious - it's my most thoroughly commented to date and may be able to give you some pointers.
The first thing that we have to do is create a new window class. Let's call it Guide.
class Guide < Window_BookOkay, so we've opened our class. Now we need to define our initialize method. It will contain our definition of @pagetext.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super endSorry about how long those text lines are, but going down to a new line and having indentations causes the formatting to be hideous when the text is drawn. Anyway, as you can see, we're able to use control characters from the game's message windows in our text. Always make sure to use two (rather than one) backslashes for the control character, and that it is attached to the first word/character that it is intended to affect. I skipped page 1 because we'll do that a little differently - we're going to center the text for it and place it near the top of the page, as it's the cover of the book.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super end def draw_page1 x = (contents_width - text_size("Game Guide").width) / 2 y = (contents_height - line_height) / 4 draw_text_ex(x, y, "\\c[14]Game Guide") endHere we find the center of the book page horizontally and 1/4 of the page vertically, then draw the text there. Now we have five pages in our book (four in the @pagetext hash and one defined explicitly), so the next thing we should do is define max_pages.
class Guide < Window_Book def initialize @pagetext = { 2 => ["In this mini guide you will be given a basic introduction to playing the game. I hope it proves informative."], 3 => ["\\c[16]Button Controls:", "", "\\c[16]Movement:", "Use the direction keys to move your character on the map, and your cursor when in menus. Hold down Shift to run. When you are in a character-related menu, you can use Q, W, PgDn, and PgUp to move between characters.", "", "\\c[16]Opening the Menu:", "Press X, 0 on the number pad, or Esc to open the menu when you are on the map.", "", "\\c[16]Selection:", "Press Z, Space or Enter to interact with characters and items on the map, or to make a selection when in a menu.", "", "\\c[16]Cancelling:", "Press X, 0 on the number pad, or Esc to go back in a menu or cancel a choice."], 4 => ["\\c[16]File Operations:", "", "\\c[16]Saving Your Game:", "Select \\c[16]Save \\c[0]from the in-game menu and choose a slot in which to save your game.", "", "\\c[16]Loading Your Game:", "If you are currently in the game, return to the title screen. Select \\c[16]Load Game \\c[0]and choose the slot you want to load."], 5 => ["Have fun, and good luck!"] } super end def draw_page1 x = (contents_width - text_size("Game Guide").width) / 2 y = (contents_height - line_height) / 4 draw_text_ex(x, y, "\\c[14]Game Guide") end def max_pages; 5; endendThere we go! As you can see, I ended the Guide class after defining max_pages. Why? Because it's done! We created a five-page book in 20 lines, and 7 of those were used to define the contents of the pages! Isn't that easy?
We're not quite done, though. We have one more task ahead of us: calling the window for display. Prior to version 1.3, this had to be done by creating a new class and calling that. 1.3 introduced the Scene_Book class, which simplified this for basic users - advanced books will still need their own classes if they're going to be used for anything but simple reading. To call the default book scene with the guide, put this in an event:
show_book(Guide, Scene_Map)That will display the book, as I've added the show_book command to the Game Interpreter class. You could also use this:
SceneManager.goto(Scene_Book)SceneManager.scene.set_book(Guide, Scene_Map)show_book is a little faster, though. You can replace Guide with the name of your book to show whatever you'd like - let's say we have a book window named Biology_Textbook. We would use this:
show_book(Biology_Textbook, Scene_Map)Note that show_book will return to the scene that you enter as its second parameter when the book is closed. It defaults to Scene_Map if no scene is given - I simply included Scene_Map in the examples to show that you can designate a scene.
That's it! Congratulations, you've created a guide! Your players will never have to puzzle over the controls again!
Anyway, I hope you can see how easy it is to use this as a base to make your own books. I can't wait to see what you come up with - make sure to let me know if you use it! Feel free to read over the rest of the script if you're learning to write code or are simply curious - it's my most thoroughly commented to date and may be able to give you some pointers.
This script is available from SES VX Ace.
Installation
Place below Materials and above all other custom scripts, or with the Window_* classes if you want to keep things organized.
Credit and Thanks
- Enelvon
This script is made available under the terms of the MIT Expat license. View this page for more information.
Edit: Just noticed how hideous my tutorial became due to the formatting. Fixed that.