Changing text color of actions

Hi guys,

I don't know if this has been asked before, so I apologize in advance. I found a similar topic but it didn't really answer my question + it had been closed already. (I don't even know if this is possible at all, but I thought I'd give it a shot.)

Is there a way to change the color of the actions (if I formulate this right)

like

  • look at object (a different color)
    You're looking at an object (color defined in display tab)
  • take object (a different color)
    You take the object and put it in inventory (color defined in display tab)

I think in my game it would help the player differentiate better what she/he is doing and the text result since the command bar is disabled and it solely relies on mouse input.

can it be done?

thanks in advance,


So you want to change the colour of the {command:} links, did i understood you right?

SetLinkForegroundColour is probably what you are looking for. It's used just like SetForegroundColour with an RGB value or a colour name, and after it was called, all new links should be in that colour.

You may have to rapidly change it between printing out new commands, or use a style template or something.

It defenitly can be done.


I thought the OP was asking for the ability to change the colour of echoed commands. If that's not what you're after, feel free to ignore me.

The obvious way to do that would be to find the line that prints out those commands. Find the core function HandleCommand (it's in your game, but will be hidden by default; ask someone who's more familiar with the desktop version of quest if you need help finding it), and in that function look for the lines:

  • msg ("> " + Left(command, LengthOf(command) - LengthOf(key)) + "{object:" + object.name + "}" )
    and
  • OutputTextRaw ("> " + SafeXML(command))

You could change those lines to make the output text a different colour.


**Or** an alternate way to do it if you're using the web editor (which can't be made to show the core functions).

Instead of making changes in Quest, we override the javascript function instead:

addText = function(text) {
    if (getCurrentDiv() == null) {
        createNewDiv("left");
    }
    if (savingTranscript) {
        SaveTranscript(text);
        ASLEvent("UpdateTranscriptString", text);
    }
    getCurrentDiv().append(text).children('span').each(function () {
      if ($(this).text().match(/^> /)) { $(this).css({color: '#ffaa00'});}
    });
    $("#divOutput").css("min-height", $('#divOutput').height());
}

That will modify the output as it's sent to the screen, causing any lines starting with > to change to color #ffaa00. In most cases, this will only affect the echoed commands.

If you're on the web editor, the easiest way to add the javascript would be putting it in the "UI Initialisation" script (on the "Advanced Scripts" tab of the game object; you might have to enable it on the "Features" tab first). You'd wrap it in Quest code like this:

JS.eval("$(function(){addText=function(t){null==getCurrentDiv()&&createNewDiv('left'),savingTranscript&&(SaveTranscript(t),ASLEvent('UpdateTranscriptString',t)),getCurrentDiv().append(t).children('span').each(function(){$(this).text().match(/^> /)&&$(this).css({color:'#ffaa00'})}),$('#divOutput').css('min-height',$('#divOutput').height())};});")

And a slight tangent… can we please make this easier?

I've looked into this before, and been somewhat confused by the way echoing commands is handled. Seems to me it would make sense to have it made into a function, rather than having this code in CoreParser.aslx. The inconsistent creation of object links in the command is also kind of weird; only if they're in the metadata dictionary, and only if they're at the end of the command?

I'd suggest that it would be easier to have a function for echoing the user's command, and call it either before running the actual command (in ResolveNextName) or before reporting that the command wasn't matched. This would allow the function to include object links for all matched objects, as well as some kind of syntax highlighting (like turning the unresolved object red).
Possibly even have it check for a script attribute to run instead, allowing the user to override the behaviour of the echo.


Thanks for the reply everyone,

I took a look at your code mrangel and to be honest I'm still a complete beginner when it comes to this stuff. I just started a few weeks ago and this goes beyond me as of right now :) I did print out your reply, perhaps some day in the future when I'm a bit more experienced in coding I will give it a try. I do think it's an interesting feature to have various colors, but as of right now I'll stick to what I already learned.

Nevertheless, thank you for your time, I do appreciate it!


That's why I tried to include both an explanation of what I'm doing, and a line of code that you can paste in without needing to understand it.

Unfortunately, I made a silly mistake, so as posted it wouldn't work. I've now edited the post to fix that.
If you go to the features tab and tick the box for "Show advanced scripts for the game object", and then on the "Advanced Scripts" tab look at the first script ("User interface initialisation script"), you can go to code view and paste the script I included above:

JS.eval("$(function(){addText=function(t){null==getCurrentDiv()&&createNewDiv('left'),savingTranscript&&(SaveTranscript(t),ASLEvent('UpdateTranscriptString',t)),getCurrentDiv().append(t).children('span').each(function(){$(this).text().match(/^> /)&&$(this).css({color:'orange'})}),$('#divOutput').css('min-height',$('#divOutput').height())};});")

That should be all you need. You can change 'orange' to whichever colour you prefer.

Sometimes, understanding the script is necessary to use it. But in this case, it should just work.


Aah, nice! I do understand that. Thanks! I'm going to try that.


Just tried it and it works wonderful! Thanks again for all the help!


Seriously, my game looks 10 times better now somehow! Very cool!


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

Support

Forums