Glulx text colour change on the fly in 6G60/6H98

I’ve been trying to change the colour of one of the Glulx Text Effects custom styles on the fly during a game, so that text in the same style could change colour onscreen, without luck. I notice that the initialising of the colours in that extensions is done even before the virtual machine is booted.

I’ve searched this forum for info, and there’s a mixture of ‘It’s hard to do / requires voodoo / not worthwhile.’

If you run Aotearoa, it does it at the intro, and can do it anytime in game in response to a typed command. And I don’t think it even opens or closes windows to pull this off because the scrollback doesn’t budge. So it makes it look easy enough.

Does anyone know what the mechanism for this is?

I probably will write the author if no-one is able to answer. Thanks.

-Wade

It’s not possible to change the style of text that’s already been displayed in Glulx. I don’t know what Aotearoa was doing, but I’d guess using switching between multiple pre set styles.

Ah!.. So, maybe if I added hooks for more than the 2 built in custom styles from Glulx Text Effects, I could then call on these to display text in many more colours at different times. That would actually cover my needs, as nice as text on the screen actually seeming to change colour before one’s eyes would have been.

For the nth time, thanks Dannii.

-Wade

If you’re still in 6G60, then you could grab these phrases to choose every possible style.

I’ve just been wrapping my head around your version of GTE.

Hm, what I was trying to do was have 9 user styles (ie 9 different colours). So the built-in number of styles is 11 in total?

I already use normal, italic, bold, fixed and alert, (edit: and note, and header, and input,) so that would leave me with 3 if I just redefined ones I’m not using to be the colours. That’s a bit of a comedown from 9.

Is there any chance I can define some constants to create more user styles (the way I did to create more sound channels in Multiple Sounds), or is this stuff too hardcoded and I’m wading into a great big pain? I have to remind you that I don’t program in i6, though I have shown a minor talent for hacking bits of it to do my bidding from time to time.

-Wade

I just hacked up something based on the older version of GTE which compiled, and to my great surprise, allowed me to change amongst 9 user styles (ie I added 7 new definable styles). I just want to check this isn’t guaranteed to break based on some obvious i6 thing I don’t know about!

So, I included this before Glulx.i6t:

Constant style_User3 11; Constant style_User4 12; Constant style_User5 13; Constant style_User6 14; Constant style_User7 15; Constant style_User8 16; Constant style_User9 17;

And I added The special-styles are special-style-1, special-style-2, special-style-3, special-style-4, special-style-5, special-style-6, special-style-7, special-style-8, special-style-9

And I added the styles to the table, and I added lines like

To say special-style-3: (- glk_set_style(style_User1); -)

And that was it.

I saw a constant in glulx.i6t which said ‘Constant style_NUMSTYLES 11’. That makes me wary, since I’ve not ‘changed’ or replaced that (if it’s defining that there are 11 styles?) and I don’t know how.

But, uh, what does anyone think about this hack?

-Wade

Update on the hack: OK, it worked with 7 extra styles in the naughty Zoom interpreter in the IDE, but in Gargoyle, only the first two styles function. That said, nothing’s crashed. That makes me think in my layman’s gut that if someone can tell me how to up that ‘numstyles’ thing from 11 to 18, that it will work!

-Wade

Glk only has 2 custom styles. If Zoom supports more then that’s a bonus, but I don’t think anything else will. Does the coloured text have to be in the main window? You could get away with overwriting the built in styles in a secondary window.

Yeah, I’m after it in the main window. I’ve got a tutorial mode ‘voice’ which uses another colour. Now since I can’t guarantee that the user’s background is white, I want to allow them to change the voice’s colour from in the game. Some would say ‘The user can set all their colours,’ but I don’t believe in that degree of putting things on the user. Especially if we’ve only got Gargoyle, where doing so requires editing a textfile.

I don’t understand when you say it only has 1 custom styles, though. Does it not have 2?

-Wade

That was a typo sorry! Yes it has 2 custom styles.

What about specifying the background colour? That’s pretty reliable.

I’m keen to stick with my original idea, but I’ve decided I could now get maybe 5 or 6 styles instead of 9, by replacing default styles my game will never invoke.

I have a couple of questions about those styles.

‘alert’ style – is it used for anything other than printing messages of the kind 'end the story saying (blah)?

And, how can I tell in what instances ‘note’ style would be invoked?

-Wade

I don’t really remember sorry. You might be best to go through the compiled I6 code and check all uses of glk_set_style().

Thanks for the tip. Hm, well I looked up ALERT_VMSTY in my compiled game and in terms of appearing in a specific context, the only one I see is in [ PRINT_OBITUARY_HEADLINE_R, so that looks promising, since I don’t ever use ‘end the story saying’, etc.

And the only place I see NOTE_VMSTY is in [ NotifyTheScore; . And I don’t use any score notifications or visibly turn them or or off, either.

So I’m gonna give this a shot.

-Wade

I’d recommend checking glk_set_style() because some code might not use those constants and might use the numbers directly. You’re probably fine to change them though.

Yeah, I started out that way but there were suspiciously few incidences. So then I just started nosing around. Having checked both ways, I think I will be OK.

My next challenge is - I’d rather use your Glulx Text Effects, but I’ve got a lot of my own code wedded to the old one. Plus there are Glimmr Extensions which depend on and include the old one, etc. I may need to marry bits of the two.

-Wade

It was a shotgun wedding.

-Wade

I seldom bother mentioning this, because there’s no need to antagonize anybody – but maybe just this once, because the topic of this thread is so specific.

If you want to use a lot of different text styles in your game, you might consider switching to TADS. It uses basic HTML coding for text output, so you can have as many sizes and colors as you choose, and as many fonts as your end user’s machine provides.

Eric Eve’s adv3lite library makes TADS significantly easier for the new author, and it supports several I7-style features, including Scenes. (Of course, non-Windows authors will have to get along without the nice IDE, which is a factor.)

Just to pick up on an earlier point:

On closer inspection, what Aotearoa does is give a choice of only 4 styles in the main window. Two of them are non-coloured, pre-defined Glulx styles, and the other two are the user definable styles, which have been defined as colours.

The place where it offers heaps of colour choices is up in the Status Window, where one can get away with that thanks to Erik Temple’s Glulx Status Window Control extension.

  • Wade

Dannii - what do you mean about the background colour? Of the screen? Of the fonts themselves?

On the latter point, I’ve got new pains.

I’ve used your new GTE extension to get my 6 coloured styles. They work fine on a white background.

Now, if the player has set their background colour to something else within the interpreter, different things start happening depending on the interpreter.

In Gargoyle, all game text appears with a local white background, including the normal style, which I didn’t redefine. I see that GTE lets you assign a local background to text colours, but what if you want whatever background already exists / what the user provided?

ASchultz tested the program in Glulxe on a PC, and what he got was - first, normal text printed correctly (the specified colour appeared on the background colour chosen by the user), and coloured text which I’d achieved by overwriting default styles also appeared correctly. But when it came to the 2 user defined styles, they appeared with local white backgrounds. I hadn’t defined a background colour for them.

Obviously, what I want is - colours that I specify, or which were already specified by Glulx, appearing as those colours on the user’s chosen background colour in any circumstances.

Do you or anyone else have advice on things I’m missing or steps I can take towards this goal?

-Wade

You said “Now since I can’t guarantee that the user’s background is white” so I was just saying that setting the background colour isn’t something that interpreters have trouble with, AFAIK. But if you want the user to be able to pick their background colour, it could be trickier.

I haven’t had any trouble like what you’re saying. My guess would be that maybe the gargoyle ini file is setting background colours for the text styles? I don’t know what would cause the Glulxe behaviour you reported. Can you share the relevant code?