Is this an issue?

Here are two bits of code that I thought should produce the same result but they don't. Can anyone explain?

msg ("<center>line 1</center>")
msg ("<center>line 2</center>")
msg ("<center>line 1<br/>line2</center>")

It looks like the output of each msg is wrapped up in a <span> element, to have them treated as separate paragraphs. <br/> is used to represent a new line within a paragraph. I'm not sure if it varies between the different stylesheets on offer, but if your CSS specifies a space between paragraphs, or an indented first line for a paragraph, there would be a visible difference. The first outputs 2 paragraphs, the second a single paragraph with a linebreak in it (like if you press shift+enter in Word; it doesn't put any spacing between the paragraphs, and acts weirdly in a fully justified para).


Thanks mrangel. I guess it seems odd to me because without centering there is no break and the following two code fragments produce the same result.

msg ("line 1")
msg ("line 2")
msg ("line 1<br/>line2")

Ah… on the default style doesn't actually include space between paragraphs (though I always set it to, because no space between lines is weird). So on my game your first code would put a space between them but the last wouldn't, with or without the centering.

But the <center> element displays the enclosed text centred within a box; it's a shorthand for <div style="text-align: center;">. And that box may have a margin around it, or padding within it.

So it makes a difference whether you have two boxes, or two lines within the same box.


(Not 100% sure about this, because I've not looked at Quests stylesheets… just guessing based on the way CSS works in general)

Possibly also worth noting that I think msg ("<center>line 1</center><center>line2</center>") would put spacing between them as well; because the <center> element creates a box with some amount of space around it, forcing the text within to appear on a new line even if it isn't already.

If you want to remove the spacing, you could do:

msg ("<center style=\"margin: 0; padding: 0\">line 1</center>")
msg ("<center style=\"margin: 0; padding: 0\">line 2</center>")

or Quest's preferred method:

SetAlignment("center")
msg ("line 1")
msg ("line 2")
SetAlignment("left")

Here are two scripts which don't produce the same.

msg ("<center>line 1</center>")
msg ("<center>line 2</center>")

This will print:

line 1

line 2


PrintCentered ("line 1<br/>line 2")

And this will print:

line 1
line 2

Just to be sure, the problem is the different font size of line 1 and 2? This problem didn't happen using the PrintCentered function.
Edit: No, start to see things here. There was a missing space and I thought the text was smaller.


Thanks mrangel, didn't know about SetAlignment!


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

Support

Forums