New and confused (and old).

-=Darchy=-
23 Oct 2017, 11:35

Hi all,

I'm a new user to Quest and to be honest fell in love with it from the off. Being an 'old' guy that used to spend the 80s running around caves with a 'plover's egg', I felt after ahem! amount of years I would have a go at doing my own. So in I jumped.

I have made a start after 3 days and taking snippets here and snippets there, I decided I needed to list some topics in an ASK/TELL format. This in itself is not too difficult a task, but I am somewhat of a perfectionist and believe I am going about this the wrong way.

I have a list of things to be shown, but I want them to be in a different colour, BUT, here is the thing, I can add colour to all text except expressions unless I do this:

msg ("Things to ask about include:")
SetForegroundColour ("Orange")
foreach (t, game.topics) {
msg (t)
}
SetForegroundColour ("Chartreuse")
msg ("[End of Topics]")

Now this works, but I have to put the 'msg ("[End of Topics]")' at the end otherwise it changes the Input Carat to the last used colour. The 'msg(t)' is the expression I wish to attach colour to, without using 'SetForegroundColour'. Is this possible?

Thanks in advance,

-=Darchy=-


K.V.
23 Oct 2017, 11:47

Hello,

This should help:

msg ("Things to ask about include:")
foreach (t, game.topics) {
  msg ("{color:Orange:" + t + "}")
}

You could also go old-school:

msg ("Things to ask about include:")
foreach (t, game.topics) {
  msg ("<span style=\"color:orange\">" + t + "</span>")
}

style=\"color:orange\"

You have to cancel out those " by replacing them with \" in code view (and when you have the text input field set to an expression), otherwise Quest will throw an error.


You may know this, but...

" + t + " inserts the variable into the string, just like JS.

So, these two are identical:

msg (t)

msg ("" + t + "")


This link is helpful, as well:

http://docs.textadventures.co.uk/quest/text_processor.html


I can add colour to all text except expressions

Do you mean the hyperlinks?

We could help with that, too, if so.


-=Darchy=-
23 Oct 2017, 12:55

Thank you K.V for a very quick response.

This works for me better than expected and I can drop the last line that I was using as a fix that looked a little 'off'!

msg ("Things to ask about include:")
foreach (t, game.topics) {
msg ("<span style="color:orange">" + t + "")
}

Not only have you helped with the main problem, but also, I feel may have given me future fixes with the variable into string part.

I thank you whole heartedly

-=Darchy=-


K.V.
23 Oct 2017, 13:44

Happy to help!

Be sure to watch those quotation marks, too. (They give me problems quite frequently.)

I'm sure you have it correct in the game, or you'd be cursing me rather than thanking me, but, just to avoid any future frustration, it should be msg ("<span style=\"color:orange\">" + t + "</span>").

If you have msg ("<span style="color:orange">" + t + "</span>"), you get this:

Things to ask about include:
Error running script: Error compiling expression '"<span style="color:orange">" + t + "</span>"': SyntaxError: Unexpected token "color" <IDENTIFIER>; expected one of <EOF>Line: 1, Column: 15


This is where things get a little tricky when using the old-school method.

You can just use {colour:orange:YOUR TEXT HERE.} rather than <span style="color:orange">YOUR TEXT HERE.</span>, and not worry with the rest of this post.


The following is definitely helpful, but it may be a trifle off-putting.

When editing in code view, you always need to escape any quotation marks inside of your string.

This is an example of an empty string: msg ("")

Any quotation marks besides the two you see there need to be escaped like this \", unless you're printing a variable, like "+ t + " in this example. Quest thinks the second unescaped quotation mark it finds ends the msg, unless you use a + to tie in a variable.


It also makes a difference whether you have expression or message selected in the dropdown when editing in the GUI.

This is what this should look like in this instance:

image


This must be an expression because of the variable.

If we tried this as a message, like this:

image


...we would get this:

Things to ask about include:
Error running script: Error compiling expression '""<span style=\"color:orange\">" + t + "</span>""': SyntaxError: Unexpected token "color" <IDENTIFIER>; expected one of <EOF>Line: 1, Column: 19


If we just wanted to use a message instead of an expression here, we could do this:

image


You can't use the text processor to print a local variable (which is what t is in your loop), but it will print a global variable. So, we set game.tempVariable to t, and it works.

Also note that I removed the \ from the text. There is no need to cancel out your quotation marks when the dropdown is on message.

The opening and closing quotation marks are also unnecessary when you are using the message text input field.


-=Darchy=-
23 Oct 2017, 14:08

I was indeed trying to use the text processor to work out the colour issue, so I believe that was where the headache came from owing to the fact I was just unaware of the "" to ignore the quotation marks . Your code worked first time (to the sound of a wahoo!) - Even playing around with it I can create a numbered list using a counter.

The text processor however was useful for me when I was showing a colour coded message based upon a 'switchedon' state message [green] and a 'not switchedon' [red] so that I could make a complex binary three light system with visuals to help keep track of the locked door state.

I will admit I was missing { } at times as my eyesight is a little on the blurred side and kept putitng in ( ) - this information is most helpful. Thanks.

-=Darchy=-


K.V.
23 Oct 2017, 14:29

You're welcome!


I just found Quest in June, and those were things that messed me up at first.


Happy gaming!