Font color shenanignas

Silver
There's a Quest idiosyncrasy where if you have a text color change FOR A MAD MOMENT but then you want the text to turn back to normal on the next bit of text that's fine; it works. But the parser only changes colour after the main text does.

You are running down a ravine.

A boulder races after you

>Have a cup of tea

Instead it should be

You are running down a ravine.

A boulder races after you

>Have a cup of tea,



tends to happen. The color correction in the script should happen pre-parser not afterwards imo.

jaynabonne
I believe I ran into that problem myself. The recommended workaround was to use HTML style tags instead of the set text color API (which seems to be intended for more long-term changes).

Silver
Something else in the very long list of things I need to learn then. :D

I guess it's something that needs to happen from the outset rather than when you're knee deep into writing a game though?

jaynabonne
As an example, instead of doing:

SetForegroundColour("red")
msg("This is some red text!")
SetForegroundColour("white")

you can do:

msg("<span style='color:red'>This is some red text!</span>")


Not the prettiest thing, but it does work. And you can colorize indvidual words (put spans just around what you wish) or define an overall style with style sheets. (Ask if you'd like an example of that.)

Silver
Coincidentally I decided to have a look at Quest in code view yesterday. But it appears it opens the entire thing rather than the page I was looking at (Actually I'm guessing there too, it was all Greek to me when I looked at it).

Silver
ok I give in, where do I put that code? It would solve a number of issues I'm currently having and seems a lot simpler than faffing with the script.

jaynabonne
It's not so much code as it is markup. So anywhere you're printing a message, you can use it:

Editor Sample.jpg


It's actually harder entering the markup in code view because both the source's XML and the HTML tags use things like <> for elements, so you have to use CDATA to properly escape it in code view... not the most fun thing. (Try looking at the source after doing something like the above, and you'll see.)

Silver
I didn't think of putting code in the message (despite me already doing it with italics tags - doh!

I'd like to learn about style sheets now please! :D

jaynabonne
Attached is an example. (Inline here as well.)

<!--Saved by Quest 5.5.5328.26617-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="testbed3">
<gameid>d7aa6b29-5319-443f-b588-398262d962b2</gameid>
<version>1.0</version>
<css><![CDATA[
<style type="text/css">
span.keyword { color:#c0c080; font-style:italic }
span.hint {color:#80A01E; font-size:10pt; }
</style>
]]></css>
<start type="script">
msg(game.css)
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<enter type="script"><![CDATA[
msg ("There is a <span class=\"keyword\">magic table</span> in the corner of the room.<br><br><span class=\"hint\">You can't click keywords, but you can type them.</hint>")
]]></enter>
<object name="player">
<inherit name="defaultplayer" />
<object name="box" />
<object name="ball" />
</object>
</object>
</asl>

There are various ways to do it. The approach I usually take is to have a string attribute on some object that will hold the CSS (style sheet) text. When you print (msg) the CSS string (or better yet, Print Message (no line break)), it gets injected into the page, and the styles are active. The downside is that if you clear the screen, you will lose your styles! I usually have my own clear screen function, which calls the Quest one and then outputs the style sheet.

The other problem with string attributes is that they don't show a multi-line edit field in the editor, so they're a pain to enter that way. I usually have to resort to code view to get them in properly.

So the steps in the sample file are:
1) Define a "css" string somewhere with your styles as a standard css style sheet.
2) Output that css string before you use the styles to get the styles into the page.
3) Reference the styles as "class" attributes of the spans (or divs or whatever you wish) when you output the content.

Using this technique with divs and css styles, I've been able to create fairly complex layouts - whatever you can accomplish with HTML/CSS.

There is a function in Quest that allows you to add external style sheets. It's used primarily to inject Google Fonts. In the past, we've tried to use it to inject our own local style sheets, with no success. I'm not sure if this was ever fixed.

The important things about style sheets are that, first, you can define all your styles in one place; second, you separate the content from how it's styled; and third, you can have a single definition for elements that are used repeatedly (e.g. you can have mulitple pieces of string with the "keyword" class, and if you change the style sheet in that one place, they all change style).

Silver
jaynabonne wrote:As an example, instead of doing:

SetForegroundColour("red")
msg("This is some red text!")
SetForegroundColour("white")

you can do:

msg("<span style='color:red'>This is some red text!</span>")


Not the prettiest thing, but it does work. And you can colorize indvidual words (put spans just around what you wish) or define an overall style with style sheets. (Ask if you'd like an example of that.)


This solved the problems perfectly. Especially as it had started to become a nightmare as I didn't know what colour to reset the text, as it could have been in one of two possible states. So it was needing complex IF scripts checking on flags setting the background and then setting font colors accordingly. I think I'm growing to like code.

I have no idea what to ask about style sheets as I neither know the capabilities and as such what, if anything, I want to do with it.

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

Support

Forums