Dynamic color changes in glulx

I’m trying to make it so that a few pages in a book are written in different colors.
My book is actually a list of text, and when reading it, a number is incremented to show which entry in the list we’re reading.
In my reading check, I want to make it so that if we’re reading an arbitrary entry in the list, to change the color as noted below:

Table of User Styles (continued)
style name justification obliquity indentation first-line indentation boldness fixed width relative size glulx color
special-style-1 left-justified no-obliquity 0 0 regular-weight proportional-font 0 12530621

I’m fairly sure this is correct, but here’s my problem:

I have this buried in a tab and colon block (check reading:, if entryNum is 4) and so the table fails to be read as such. If I try to hug it to the left side so the table works, the tab and colon block fails.

Is there a way to put a color style changing table inside an if block?
I’d like to do this six times with different colors, so I can’t just set special-style-1 and special-style-2 and leave it.

You can change Glk style settings at any time, but the changes only apply to new windows. Furthermore, only 11 styles are defined, and the bulk of these are used for styling conventional IF output.

Unless you’re displaying the book pages in a dedicated window, you probably don’t want to change anything except the two user styles. If you’re careful, you can modify styles that would otherwise not be used, like BlockQuote. Overriding the defaults for Emphasized, Note, and Alert would bring you to six, though you’d need to avoid italics elsewhere, turn off score messages, and change the way end-game text is printed.

The forthcoming Glk CSS spec promises to make this somewhat less painful.

Yes, this is exactly what I want to do, now how do I do it in the condition I detailed above?
Can I change the text color of the two user styles without using a table?
Or how do I put a table inside of an if block?

A table is a standalone structure. You can’t put one inside of an if block, because tables don’t go inside any execution blocks at all. As Ben said, Glulx limits you to two custom styles. To get a few more styles, you can repurpose some of the built-in styles (such as blockquote). This is an especially good option if you’re using a dedicated window–which it sounds like you are–because the chances that the second window will need all the styles is fairly slim. If you’re not accepting input in the new window, you won’t need the Input style for example. You may not need the Header style if you aren’t showing room descriptions in it, etc.

Another good thing about using a second window is that you can reboot the styles: If you change the definition of those styles before you open the new window, then the old window will retain the original style (because a window’s styles can’t change once it has been opened), but the new window will use the new styles. You can even close and immediately reopen the second window, changing the styles before you reopen it.

How to change the styles, though? Glulx Text Effects is really designed for one-window work. A small tweak will make it work much better for your purposes. Open up GTE and change the first line of this block of code (the bold type indicates what’s to be changed):

Then add this line to your code (or to GTE, if you like):

Now you can make as many tables as you want (with different names, call them whatever you want); they all will have to have the same format. Before opening a new window with Flexible Windows, switch to the table you want to apply to that window, then reset the styles. For example:

Carry out opening the book: now the current style table is the Table of Book Styles; initialize user styles; open up the book-window.

Caveat: I haven’t tested any of this, so I may have left out a detail or two, but the overall method ought to be sound.

–Erik

Thanks for the replies, it’s very helpful.
However, I’m reading that I can’t do what I want to do.
Here’s what I want to happen:

read book
Here is the text of the first page
There are more pages in the book.

g
Here is the text of the second page
There are more pages in the book.

g
Here is the text of the third page
There are more pages in the book.

g
Here is the text of the fourth page
This is the last page of the book.

But it looks like that can’t happen in glulx. It looks like that might be possible in a z-code game, but unfortunately, my project is too large to fit in a z8.(I’m only about 10% done with the game and it’s 380K)
Oh, well. I’ll have to just abandon this idea then.

As a further elaboration: the restrictiveness of text coloring in Glulx is something that a lot of people dislike, and there has been some discussion about changes to the specs to allow more options. So it may change down the line, but things aren’t settled yet, and you’re probably wise not to expect this feature to appear in the very near future.