• Hi, Guest!
    Some images might be missing as we move away from using embedded images, sorry for the mess!
    From now on, you'll be required to use a third party to host images. You can learn how to add images here, and if your thread is missing images you can request them here.
    Do not use Discord to host any images you post, these links expire quickly!
Textbook Script

v19 Textbook Script N/A

This resource pertains to version 19 of Pokémon Essentials.
Pokémon Essentials Version
v19.1 ➖
1615862994033.png
To see this script in action, check out The Last Nurse Joy!

Love lore dumps but hate scrolling through little textboxes? Boy do I have a script for you!

Code
Paste in a new script section above Main!
Ruby:
#books
BookZero = [
"TITLE","This is the text of your book.\nThis is on a new line.<i>This text is italicized</i>, but this is not.",
"PAGE 1","<fs=28>This is the next page. See how the left arrow appears now?\nThe text is also bigger!</fs>",
"PAGE 2","<fs=22>Here's the last page! The right arrow has disappeared. The text is smaller, so I could write a lot more! But I won't.</fs>"
]

BookOne = [
"TITLE","Here's another book! This one only has one page!"
]

Books = [
BookZero,
BookOne
]

def textbook(book)
    scene = Textbook_Scene.new
    screen = TextbookScreen.new(scene)
    screen.pbStartTextbookScreen(book)
    yield if block_given?
    pbFadeInAndShow(@sprites)
end


class TextbookScreen
  def initialize(scene)
    @scene = scene
  end

  def pbStartTextbookScreen(book)
    @scene.pbStartTextbookScene(book)
    ret = @scene.pbTextbookScene
    @scene.pbEndScene
    return ret
  end

end


class Textbook_Scene

  def pbUpdate
    pbUpdateSpriteHash(@sprites)
  end

  def pbStartTextbookScene(book)
    @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
    @viewport.z = 99999
    @page = 0
    @book = book
    @bookarray= Books[book]
    @max=Books[book].length#)+4)/2
    #@max+=4
    #@max/=2
    @sprites = {}
    @sprites["background"] = IconSprite.new(0,0,@viewport)
    @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
    pbSetSystemFont(@sprites["overlay"].bitmap)
    @sprites["leftarrow"] = AnimatedSprite.new("Graphics/Pictures/leftarrow",8,40,28,2,@viewport)
    @sprites["leftarrow"].x       = -4
    @sprites["leftarrow"].y       = 10
    @sprites["leftarrow"].play
    @sprites["rightarrow"] = AnimatedSprite.new("Graphics/Pictures/rightarrow",8,40,28,2,@viewport)
    @sprites["rightarrow"].x       = (Graphics.width)-36
    @sprites["rightarrow"].y       = 10
    @sprites["rightarrow"].visible = (!@choosing || numfilledpockets>1)
    @sprites["rightarrow"].play
    drawTextbookPage(@page)
    pbFadeInAndShow(@sprites) { pbUpdate }
  end

  def pbEndScene
    pbFadeOutAndHide(@sprites) { pbUpdate }
    pbDisposeSpriteHash(@sprites)
    @viewport.dispose
  end


  def drawTextbookPage(page)
    book   = @book
    @sprites["leftarrow"].visible = (@page>0)
    @sprites["rightarrow"].visible = (@page+3<@max)
    overlay = @sprites["overlay"].bitmap
    overlay.clear
    base   = Color.new(0,0,0)
    # Set background image
    @sprites["background"].setBitmap("Graphics/Pictures/textbookbg")
    imagepos=[]
    # Write various bits of text
    pagename = @bookarray[page]
    textpos = [
       [pagename,Graphics.width/2,10,2,base]
    ]
    #For title size
    @sprites["overlay"].bitmap.font.size=32
    pbDrawTextPositions(overlay,textpos)
    @sprites["overlay"].bitmap.font.size=26
    text=@bookarray[page+1]
    drawFormattedTextEx(overlay,25,35,Graphics.width-40,text,base)
  end


  def pbTextbookScene
    loop do
      Graphics.update
      Input.update
      pbUpdate
      dorefresh = false
      if Input.trigger?(Input::BACK)
        pbPlayCloseMenuSE
        break
      elsif Input.trigger?(Input::LEFT)
        oldpage = @page
        @page -= 2
        @page = 0 if @page<0
        if @page!=oldpage   # Move to next page
          pbSEPlay("GUI summary change page")
          dorefresh = true
        end
      elsif Input.trigger?(Input::RIGHT)
        oldpage = @page
        @page += 2
        @page = @max-2 if @page+3>@max
        if @page!=oldpage   # Move to next page
          pbSEPlay("GUI summary change page")
          dorefresh = true
        end
      end
      if dorefresh
        drawTextbookPage(@page)
      end
    end
  end
end

If you're using a version prior to v19, change (Input::BACK) to (Input::B)

If you're using a version prior to v18, change pbPlayCloseMenuSE to pbSEPlay("GUI menu close")

Using the script
Most of what we need to do is at the top of this script! I've included some example books to give a feel for how this works!
Ruby:
BookZero = [
"TITLE","This is the text of your book.\nThis is on a new line.<i>This text is italicized</i>, but this is not.",
"PAGE 1","This is the next page. See how the left arrow appears now?\nThe text is also bigger!",
"PAGE 2","Here's the last page! The right arrow has disappeared. The text is smaller, so I could write a lot more! But I won't."
]
Your book is just defined as an array full of strings! Your text should be in pairs- the first one's your title, and the second is your content! (If you don't want a title on your page, just put "") And you can use all the cool tricks to manipulating text that you can with Show Text- size, fonts, italics, bold, colors, opacity, just about anything! The only exceptions are:
  • Things that affect stuff like the speed of text or the positioning of the menu box, since neither exist here.
  • Things that require another menu box to be displayed- showing money/coins, \f to display a picture, choices, etc.

Remember that the array name has to be capitalized!

After that, just put your array's name in the array Books!
Ruby:
Books = [
BookZero,
BookOne
]

And to call it, just use textbook(book), with book being the number in the Books array! (Remember that it starts at 0!)

You'll need a file titled textbookbg in Graphics/Pictures! If you want to create your own, I do recommend downloading the one linked here all the same, so you can be sure your text will align!


Future Goals
  • Get a page turn sound effect, get a way to easily set custom sound effects
  • Make a way to set custom backgrounds but still be able to default to one
  • Implement a table of contents feature, to jump to pages
Credits
TechSkylander1518 for the code
AnonAlpaca for the graphic, if used
Author
TechSkylander1518
Downloads
950
Views
3,009
First release
Last update
Rating
5.00 star(s) 2 ratings

More resources from TechSkylander1518

Latest reviews

for me it is giving error when I try to leave the book. my game is 16.2 is it?
TechSkylander1518
TechSkylander1518
Ah, that's because pbPlayCloseMenuSE wasn't defined until v18. Replace that with something like pbSEPlay("GUI menu close",80) and it should be good to go!
I always like to add some lore and details of stuff on my fangame (for example, each single desk, fridge or decoration in every single house, has its own definition, even things like plants or TVs). So having an script like this is super useful for zones like Ruins, Libraries of even the Academy I have on the first City. Thanks for sharing it <3
TechSkylander1518
TechSkylander1518
Aw, I'm really happy you can put it to such good use!
Back
Top