Book GUI (Solved)

Started by Hobbes, Sun 06/06/2021 10:28:19

Previous topic - Next topic

Hobbes

Me again!

So for this game I'm working on I'm really pleased with the world map (thank you to everyone who helped with that). Using a very similar approach, I've created a "book room". It's got an empty book graphic in there and I use a GUI with 3 labels + 1 Exit button.

The labels are BookTitle, BookLeftPage & BookRightPage. Then depending on which book I click on in the real world, I set GlobalInt "which_book" to change to integer 1, 2, 3 etc. My aim is to fit all text from that book on one page. I'm not looking for Skyrim-style nonsense where you can read 80,000 words in-game. Just short and snappy lore dumping. These books are optional, but can provide some more context/understanding for people who want to engage with it. Optional world building, so to speak.

The way I set these labels is using my Book Room and under "Room_Load" I've got code like this:

Code: ags

if (which_book == 1) {
  BookTitle.Text = "TESTING THIS BOOK";
  BookLeftPage.Text = "This is a big test to see how much text I can fit into this one little iddly bitty thing just right here. If it can't fit, it can't fit. So what will happen then?";
  BookRightPage.Text = "It's a big question to which we'll never know the answer! I do reckon we can set the stage for Atlantis by finding the three rings that will bring Sun, Moon and Earth together.";
  }


This produces the perfectly serviceable and functional output:



Two questions:

1. I would like to check if the coding wizards in this forum are now cringing in abject horror at how I'm doing this. Would you say there's a more efficient way?

2. Secondly, is it possible to have line breaks in there? Since I'm inputting it as one string, I'm not sure if there's a string command that would add a new paragraph?

Thank you again for everyone willing to spend some time pondering this!

Matti

#1
Putting a single [ in the text will result in a line break.

As for the code, I don't think you could make it much more efficient.

Edit: Well, you could of course display one image per book that contains all the text, instead of using three labels. That would shorten the code significantly and you could also see if you want different or anti-aliased fonts or a bit of variety in the pages.

Cassiebsg

Simple text on a label is better for translation purposes than an image.  ;)

Just wanted to add, that you can use the String.Append (check manual for usage) to add new lines to your text.
There are those who believe that life here began out there...

Hobbes

Thanks everyone! That [ is really useful, just tried sticking [[ and it works a treat, new paragraph and everything.

I might feel brave at some point and try to script a multi-page book, which will need some counter integer and a max_page integer before the book loads... hmmmm... that could be fun! :)

eri0o

Using "\n" is better, as it's what is used in other languages. It should work too.

SMF spam blocked by CleanTalk