Can anyone explain SetAlignment ()

Greetings fellow Quest users.

SetAlignment () is causing me some minor headaches. It seems so incredibly tricky for what is supposed to be just a simple function. (This is it's documentation, for anyone curious: https://docs.textadventures.co.uk/quest/functions/corelibrary/setalignment.html)

First of all: it really onyl sets the alignment for the text that follows. I haven't found a way to make it a global setting without executing it at the start of each room/page.

This is something i can deal with, although it behaves different to any other set-function (like SetBackgroundColour).

But even worse, i see no way to use it in the Text processor, where such a thing would be most useful. Do i really have to go the detour using msg?

Can anyone elaborate more than the documentation on this function? Help is greatly appreciated.


The way Quest handles alignment is just weird.

SetAlignment will start a new div (a block of text for layout purposes) with the specified alignment.
If can't be done using the text processor, because all the text output together goes into the same div; so can't include the code to end one div and start a new one.

Several built-in features, such as clearing the screen and displaying a menu, will also create a new div. And these all force it to be left-aligned.

If you want to change the alignment of all text (including what's already on the screen), you could do:

msg ("<style>#divOutput div { text-align: right !important }</style>")

That tells it that all divs inside #divOutput (the main output area) should be right-aligned, and the important means that this will override anything that would reset it. If you then wanted to centre one line, you'd have to do something like SetAlignment("center !important") to overrule it.

However, this (invisible) <style> line would be removed along with the rest of your output when the screen is cleared; returning everything to it's default behaviour.

You could use a line like:

JS.eval("$('<style>').text('#divOutput div { text-align: right !important }').appendTo('head');")

to change the alignment of all output text, putting the <style> element in the document's header so that it isn't affected by clearing the screen. Text outside of #divOutput isn't touched when clearing the screen; but it also isn't touched when saving the game; so you'd have to do it again when the player loads a saved game.

I know it's a lot to take in, and I really wish there was a better way to do this.


Alright, thank you for your explanation.

The way quest handles this is somewhat off-putting though. I think i can work with what you gave me, but i'd rather not bother with this at all. I hope future versions of Quest get rid of this.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums