Font colors in Glulx

I have been battling this off and on for awhile. I fight with it when I don’t feel like writing the story.

I am using the compass rose in a custom status bar (borrowed from Bronze) and I like the ability to show unvisited rooms in another color. In fact, 6 different colors depending on region. In z-code this is easy. But in Glulx I can’t even get a single color to change in the status bar.

I have used the extension Glulx Text Effects by Emily Short to try and do this. I defined the tables like this:

[code]Section 7G (for Glulx Only)

Include Glulx Text Effects by Emily Short.

To say default letters: say roman type.

Table of User Styles (continued)
style name justification obliquity indentation first-line indentation boldness fixed width relative size glulx color
special-style-2 – -- – -- – -- – g-pure-red

Table of Common Color Values (continued)
glulx color value assigned number
g-pure-red 16711680
[/code]

Then try to use (in the code for the compass rose):

To say top rose: let place be the room up from the location; if the place is a apparent room, say "[if the place is unvisited][second custom style][end if]U [default letters]"; otherwise say " ";

(just a single sample line, there are many others) in the lines that write the rose marker… and nothing happens. It compiles, but the color never changes. I have even tried copying the tables directly from the examples (where they work) for the different styles like bold, italic, etc… and tried to apply them to the compass rose lines but nothing changes.

But, to add to my confusion… this works:

[code]RM is a room.

Gw is a room. Gw is north of RM.

Section 7G (for Glulx Only)

Include Glulx Text Effects by Emily Short.

To say default letters: say roman type.

Table of User Styles (continued)
style name justification obliquity indentation first-line indentation boldness fixed width relative size glulx color
special-style-2 – -- – -- – -- – g-pure-red

Table of Common Color Values (continued)
glulx color value assigned number
g-pure-red 16711680

The description of RM is “[if Gw is unvisited][second custom style][end if]U[default letters]P”; [/code]

It prints the red ‘U’ in “UP” if Gw is unvisited, and “UP” if it is visited.

Which to me, seems to be basically the same thing, just not being printed in the status bar.

Why does something as simple as color have to be so difficult? Is it because it is the status bar and not normal game text?

In z-code, it works using the basic commands for color (I have them separated into a Section 7Z) but I can not get it to work in Glulx. Any ideas?

1 Like

I ran the source text you posted, and all of the Glk calls looked fine. So there’s nothing wrong with your Inform code. My best guess is that your interpreter has opted not to honor color in text grid windows, which is legal according to the specification:

Glulx Text Effects only sets the styles associated with text buffer windows, not text grid windows. Since the status bar is a text grid window, it has no effect.

If you look at the Glulx Text Effects source, you can see Inform 6 code like

[ SetColor S N; glk_stylehint_set(wintype_TextBuffer, S, stylehint_TextColor, N); ]; To have any effect on the status bar, you’d want similar code, but with “wintype_TextBuffer” replaced with “wintype_TextGrid”.

David is correct that Glulx Text Effects is limited to changing text buffer window colors. The Glulx Status Window Control extension is the easiest way to get control over the status window.

Side note: When the new Glulx style system is ready for implementation in I7, we need to handle it better, with a far more unified approach to making Glulx functionality available.

–Erik

Oh, good catch. Sorry about my misleading answer. I saw the glk_stylehint_set call but didn’t look closely at the arguments.

After reading through the extension docs, and playing with the demo code, that seems to do exactly what I want.

Thanks. This is actually going to be easier than the way I was trying to do it, and will give me even more color options than I need. I am sure I will figure out how to use them (or misuse them). :smiley:

Okay… I can get the color change to work, but I am having no luck applying it to just one character. It is all of the status bar, or nothing. But I will keep trying.

There is one command that no matter where I use it causes a recursive type update to the status bar on loading the game (it seems to try to load it over and over, but never completes), then crashes with a message “Glulxe fatal error: Stack overflow in function call.” That command is “update the status line;”.

It always dies the same way. Without it, I can change the color of all text in the status bar (even if I just apply the change to a single character, it all changes), but even that is only on the second turn. Before that it is all white text. Second turn, all of the status bar text changes, even things I have set to not change… I know there is a clue in there… and I am still searching for it.

Just an update. As I experiment, I may come back with a real question.

Sorry, I didn’t really look back at your original request when I responded. Glulx Status Window Control isn’t intended to give you per-style controls like Glux Text Effects does–that’s why you’re having so much trouble doing anything but changing all of the colors! This is the kind of thing I meant about taking a more unified approach to Glulx support in the future: Emily wasn’t interested (I presume) in making Glulx Text Effects apply to the status window, so she didn’t implement them. I wasn’t interested in having multiple styles in my status window when I wrote Status Window Control, so I didn’t implement them–and so we have an extension that purports to give you control over Glulx text styles, which doesn’t cover text in the status window, and we have an extension that purports to give you control over the status window, but doesn’t give you control over the text styles therein…

Anyway, here’s how you can add this, using the first custom user style:

[code]Include Glulx Status Window Control by Erik Temple.

When play begins:
now the right hand status line is “[first custom style]A[roman type]ardvark”;
set color for custom user style 1 in status window to g-red;
open the status window.

To set color for custom user style 1 in status window to (color - a glulx color value):
(- glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_BackColor, ColVal({color})); -).

Table of Common Color Values (continued)
glulx color value assigned number
g-red 16711680

There is a room.[/code]

If you are using Status Window Control to create a non-reversed status window, you need to use stylehint_Color in place of stylehint_BackColor in the I6 segment. Be sure to call the style before you open the status window; if you don’t, you’ll need to reconstruct the window before the change will take effect.

I’m not sure what you might have done to cause the stack overflow error, but you probably don’t need to use the “update the status line” call. The status line is normally updated (by the library) right before input is requested. Sometimes that’s not what’s needed, but if your game follows the standard turn-based input flow, it should work fine.

–Erik

P.S. By the way, if this is all you want to do, then you don’t need Glulx Status Window Control; you can implement it without that extension, like so:

Include Glulx Text Effects by Emily Short.

After starting the virtual machine:
	now the right hand status line is "[first custom style]A[roman type]ardvark";
	set color for custom user style 1 in status window to g-red.

To set color for custom user style 1 in status window to (color - a glulx color value):
	(- glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_BackColor, ColVal({color})); -).
	
Include (-

Constant glulx_colour_table = (+Table of Common color Values+);

[ ColVal c i max;
	max=TableRows(glulx_colour_table);
	for ( i=1:i<=max:i++ ) {
		if (TableLookUpEntry(glulx_colour_table, 1, i) ==  c) 
			return TableLookUpEntry(glulx_colour_table, 2, i);
	} 
];

-)	


Table of Common Color Values (continued)
glulx color value	assigned number
g-red	16711680

There is a room.

I compiled your second version (because it seemed simpler for my purpose) and the result seems to be what I am looking for. Now I just need to fold it into my code. This is for an extension, and my goal is to make the z-machine usage look and work exactly like the Glulx.

Thank you VERY much!

As far as the stack overflow… I was testing all of the functions in Glulx Status Window Control to see what they did within my extension. And there is one thing I have found in my time working with Inform… if there is an unusual way to crash the compiler, I will find it!

Excellent. If this is for an extension, you might want to consider offering both versions: one for folks that want to use Glulx Status Window Control and one for folks who don’t. Personally, for example, I would prefer to have a non-reversed status line in my game. Other folks might want to be able to change their status bar color (e.g., as a health or danger meter), while others might want to have the status bar disappear for some sections of the game. You need GSWC to do any of these.*

Just something to think about. If you aren’t familiar, check out Chapter 25.8 for info about how to include code conditionally based on what other extensions are installed.

–Erik

  • More accurately, you need GSWC if you don’t know I6 and don’t want to have the hack the library…

I had thought of that… and had noticed how “include code conditionally based on what other extensions are installed” was used in GSCW and it seemed like a good idea for what I am doing. So that is an idea for version 2.

So far I have it working under Glulx with red as the color for unvisited rooms, just as the original z-machine version did. Of course I can never leave well enough alone, so I expanded the original to include 8 colors so the unvisited room color can change with region. Green for forest, cyan for lake, yellow for desert, etc.

In the z version it looks like this:

to say unvisited-mark: if exit-colour-num is 1 begin; turn the background red; otherwise if exit-colour-num is 2; turn the background yellow; otherwise if exit-colour-num is 3; turn the background green; otherwise if exit-colour-num is 4; turn the background blue; otherwise if exit-colour-num is 5; turn the background magenta; otherwise if exit-colour-num is 6; turn the background cyan; otherwise if exit-colour-num is 7; turn the background black; otherwise if exit-colour-num is 8; turn the background white; end if;

As you can see, exit-colour-num is a variable from the game that can be changed depending on the region, or current mood of the programmer.

Now I am trying to get the same effect in the Glulx code. Red works… but I like being able to change it as needed.

So instead of:

After starting the virtual machine: set color for custom user style 1 in status window to g-red.

I would like to be able to say:

After starting the virtual machine: Every turn: if exit-colour-num is 1 begin; set color for custom user style 1 in status window to g-red; otherwise if exit-colour-num is 2; set color for custom user style 1 in status window to g-yellow; otherwise if exit-colour-num is 3; set color for custom user style 1 in status window to g-green; otherwise if exit-colour-num is 4; set color for custom user style 1 in status window to g-blue; otherwise if exit-colour-num is 5; set color for custom user style 1 in status window to g-magenta; otherwise if exit-colour-num is 6; set color for custom user style 1 in status window to g-cyan; otherwise if exit-colour-num is 7; set color for custom user style 1 in status window to g-black; otherwise if exit-colour-num is 8; set color for custom user style 1 in status window to g-white; end if.

But it doesn’t work… and I have tried many variations of it. This is just the most recent version that doesn’t work. It compiles, but the color remains white. The use of the ‘if’ statement has caused me problems before. It never works the way I expect it to. Maybe this is why you wrote GSCW… because my way just isn’t possible? Or am I looking at the problem wrong?

Exactly so. Glulx stylehints have a major limitation in that they cannot be changed once the window is opened. Any stylehint you set on text-grid windows won’t take effect until the next text-grid is opened. So, as with the Kaleidoscope example in GSCW, you need to invoke the “reconstruct the status window” phrase after changing the color, e.g.:

Every turn: if exit-colour-num is: -- 1: set color for custom user style 1 in status window to g-red; -- 2: set color for custom user style 1 in status window to g-yellow; -- 3: set color for custom user style 1 in status window to g-green; -- 4: set color for custom user style 1 in status window to g-blue; -- 5: set color for custom user style 1 in status window to g-magenta; -- 6: set color for custom user style 1 in status window to g-cyan; -- 7: set color for custom user style 1 in status window to g-black; -- 8: set color for custom user style 1 in status window to g-white; reconstruct the status window.

“Reconstruct the status window” is a GSWC phrases that closes and then reopens the status window.

Note that your original code, which has an “every turn” rule inside a “after starting the virtual machine” rule, shouldn’t even compile. The starting the virtual machine is pretty much the earliest place in the game sequence that an author can intervene with I7 code; it happens before the status window opens and is therefore the place you need to set the text-grid stylehint if you aren’t using GSWC. (GSWC lets you open the status window whenever you want, so the same constraint does not apply.) Of course, that makes no sense alongside an every turn rule; the first every turn rule fires long, long after the virtual machine starts.

For Glulx, you might consider letting the author set the color directly. It seems cruel to limit Glulx authors to the awful Z-machine colors when they could just as easily specify their own perfectly nice ones.

Anyway, this is a good idea for an extension; a lot of people do want to include this status bar compass, and especially for Glulx, there are some hoops to jump through right now to make it happen.

–Erik

I had a feeling you were going to say that.

Okay, time for a re-write using GSCW. Probably the best way anyhow. Then the background could be changed the same way. And that could be useful, as you mentioned.

I had to laugh at “the awful Z-machine colors” comment. I agree, and it shouldn’t be hard to add that as a feature once I get the basics worked out.

And thanks again for all of your help. This has been bugging me for months. Now I see a light at the end of the tunnel, not just compiler errors. :wink:

This ended up working perfect:

[code]Include Glulx Status Window Control by Erik Temple.

Table of Common Color Values (continued)
glulx color value assigned number
g-blue 255
g-green 65280
g-cyan 65535
g-yellow 16776960
g-magenta 16711935
g-red 16711680

When play begins:
if exit-colour-num is:
– 1: set color for custom user style 1 in status window to g-red;
– 2: set color for custom user style 1 in status window to g-yellow;
– 3: set color for custom user style 1 in status window to g-green;
– 4: set color for custom user style 1 in status window to g-blue;
– 5: set color for custom user style 1 in status window to g-magenta;
– 6: set color for custom user style 1 in status window to g-cyan;
– 7: set color for custom user style 1 in status window to g-black;
– 8: set color for custom user style 1 in status window to g-white;
open the status window;

To set color for custom user style 1 in status window to (color - a glulx color value):
(- glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_BackColor, ColVal({color})); -).

Every turn:
if exit-colour-num is:
– 1: set color for custom user style 1 in status window to g-red;
– 2: set color for custom user style 1 in status window to g-yellow;
– 3: set color for custom user style 1 in status window to g-green;
– 4: set color for custom user style 1 in status window to g-blue;
– 5: set color for custom user style 1 in status window to g-magenta;
– 6: set color for custom user style 1 in status window to g-cyan;
– 7: set color for custom user style 1 in status window to g-black;
– 8: set color for custom user style 1 in status window to g-white;
reconstruct the status window.[/code]

And the opening line of the game is:

After starting the virtual machine: now exit-colour-num is 2;

To set the color before the status window is drawn. That is the reason for the first set of ‘ifs’ before opening the window. Without this, it opened to red if I had:

When play begins: set color for custom user style 1 in status window to g-red; open the status window.

And didn’t change until after the first turn. Or white if I omitted the “set color for custom user style 1 in status window to g-red;” line all together.

But it works. Now to add background color change and user definable colors.

Okay… this works too, and is much shorter:

[code]Include Glulx Status Window Control by Erik Temple.

Table of Common Color Values (continued)
glulx color value assigned number
g-blue 255
g-green 65280
g-cyan 65535
g-yellow 16776960
g-magenta 16711935
g-red 16711680

When play begins:
Every turn:
if exit-colour-num is:
– 1: set color for custom user style 1 in status window to g-red;
– 2: set color for custom user style 1 in status window to g-yellow;
– 3: set color for custom user style 1 in status window to g-green;
– 4: set color for custom user style 1 in status window to g-blue;
– 5: set color for custom user style 1 in status window to g-magenta;
– 6: set color for custom user style 1 in status window to g-cyan;
– 7: set color for custom user style 1 in status window to g-black;
– 8: set color for custom user style 1 in status window to g-white;
reconstruct the status window.

To set color for custom user style 1 in status window to (color - a glulx color value):
(- glk_stylehint_set(wintype_TextGrid, style_User1, stylehint_BackColor, ColVal({color})); -). [/code]

Okay, back to the longer version. I was able to create a situation where the shorter version doesn’t work right during testing.

Just thought I’d add the update. :wink:

Update:

I am writing the docs now, and I will probably be ready to send this extension in as a completed, and ready for the masses version in a day or two. I have added optional support for hidden doors and rooms (hiding them or showing them in the compass rose and list of exits) if the right extension is also installed. :wink:

The next version will add selectable background color for the status bar, and at least 4 user definable slots in the table of colors that can be used as text or background. I figured it would be better to get a stable version out that is 100% equal between z-machine and Glulx usage first… then work on one that adds separate functionality for just the Glulx games.

Of course if you are going to change the way all of this is done in GSCW I will just have to re-write it. But that is cool. All the more reason to work on the next version.

Thanks!