Combine Inline Hyperlinks and Hyperlink Interface?

Two extensions:

With Inline Hyperlinks, you can write a room description like this:

"The [link]bathroom[as]e[end link] is thankfully right here off the main hallway."

which will give a room description with the word “bathroom” as a link, which when clicked will take you “east” (or “e”), presumably into The Bathroom.

“[link]” starts the link, “[as]” starts what clicking on the link will do (type “e”), and “[end link]” ends the link.

However, typing “bathroom” at the parser will not take you east.

With Hyperlink Interface, you can write a room like this:

The main hallway is a room. "The [d]bathroom[x] is thankfully right here off the main hallway." Understand "bathroom" as east when location is the main hallway.

The “[d]” designates a “direction” link. The “[x]” indicates the end of the link. And “Understand…” indicates what direction you go when you click on the specified link or you type the link text at the parser.

This yields a room description in which you can click on “bathroom” to go east and you can also type “bathroom” at the parser to go east.

How difficult would it be to make an extension with the following syntax?:

"The [d]bathroom[as]e[x] is thankfully right here off the main hallway."
which would accomplish the same affect as the Hyperlink Interface code above, but with the brevity of the Inline Hyperlinks syntax?

Sorry, I don’t quite understand how that’s different from Inline Hyperlinks. Is it just the briefer syntax?

No, it also keeps the ability to type the link text at the parser to send the same command as can be done with Hyperlink Interface. But, yes, with a much briefer syntax melded from the briefest syntax of both extensions:

[d] instead of [link]
[as] “(direction)” instead of “Understand “(link text)” as (direction) when location is (room name).”
[x] instead of [end link]

Only with Hyperlink Interface can you define the word “bathroom” as a link that takes you to The Bathroom and also as text that you can type to take you to The Bathroom. But the cost is a whole heck of a lot more typing (“Understand “bathroom” as east when location is hallway.”).

You can’t define things for the parser from within say phrases - you need to use Understand statements. I think you’d be better off keeping the two things separate: inline hyperlinks, and a “go to room” command, which you could then shorten to leave out the “go to” part.

In theory the say-phrase could add entries to a table of substitutions, which are then applied to the command line before parsing. (After reading a command.)

I say “in theory” because the details get hairy.

This would be a lot of code and CPU time for the improvement you want.

Dang. I was hoping it would be simple.

Can you change tables which define kinds of value at runtime? That might be a solution, creating a hyperlink kind and rewriting the blank rows with the say phrase.

It’s not that bad, I think. Erik Temple’s Inline Hyperlinks extension already creates one list of indexed texts as it gathers the hyperlinks, so it knows what to put in the command line when a link is clicked. You can just create another list of indexed texts as you go, and if the player types a command instead of clicking a link, go through the second list checking to see if that’s been typed. If so, change the text of the player’s command to what they’d get if they clicked on the link.

This is only tested on the simplest example from the Inline Hyperlinks documentation (I don’t seem to be able to run Glulx projects in the IDE right now) and there are almost certainly some edge cases it doesn’t deal with – for instance, if two hyperlinks go to the same command – but it’s a start. Replace “Section - Placing links” in Chapter 1 of Inline Hyperlinks with the following, which just adds a couple of things:

[code]Section - Placing links

The hyperlink list is a list of indexed texts variable.
The hyperlink text list is a list of indexed texts variable. [NEW – this is the list of texts that actually appear on the screen]

The hyperlinked text is an indexed text variable. The hyperlinked text is “”.
The hyperlinked command is an indexed text variable. The hyperlinked command is “”.

To say link:
now the hyperlinked text is “”;
now the hyperlinked command is “”;
start capturing text.

To say as:
stop capturing text;
now the hyperlinked text is “[captured text]”;
start capturing text;

To say end link:
let hyperlink index be a number;
stop capturing text;
if the hyperlinked text is “”:
now the hyperlinked text is “[captured text]”;
now the hyperlinked command is “[captured text]”;
if the hyperlinked command is listed in the hyperlink list: [this I think is the part that would cause trouble if two links translate to the same command – but I think it might be possible to solve this just by deleting this block]
repeat with count running from 1 to the number of entries in the hyperlink list:
if entry (count) of the hyperlink list is hyperlinked command:
let hyperlink index be count;
otherwise unless the hyperlinked command is “”:
add hyperlinked command to hyperlink list;
add hyperlinked text to hyperlink text list; [NEW: this adds the link text that appears on the screen to the list that we’ll check against when we read a command]
let hyperlink index be the number of entries of hyperlink list;
say “[set link (hyperlink index)][hyperlinked text][terminate link]”;

After reading a command: [NEW: this is the rule that looks through the hyperlink text list and, if the player typed something that appears in it, replaces the command with the appropriate corresponding command]
let T be indexed text;
now T is the player’s command;
repeat with N running from 1 to the number of entries in hyperlink list:
if T exactly matches the text entry N in the hyperlink text list:
change the text of the player’s command to entry N in the hyperlink list;
break.

To say set link (N - a number):
(- if (glk_gestalt(gestalt_Hyperlinks, 0)) glk_set_hyperlink({N}); -)

To say terminate link:
(- if (glk_gestalt(gestalt_Hyperlinks, 0)) glk_set_hyperlink(0); -)[/code]

You’d have to make similar changes to the chapter for use with Flexible Windows, and I don’t know if it eats up a lot of CPU time anyway. But hopefully it shows that it can be done without too much blood, sweat, and tears.

OK, two links translating to the same command didn’t seem to cause trouble (at least not the exact trouble I thought) because I wasn’t understanding how the links worked. But the same link translating to two commands can cause trouble. Consider the following test case:

Northern End is a room. "You can go to the [link]center[as]south[end link]." Center is south of Northern End. "You can go to the [link]northern end[as]north[end link] or [link]southern end[as]south[end link]." Southern End is south of Center. "You can go to the [link]center[as]north[end link]."

In Inline Hyperlinks any link that’s currently on screen will be active – you can click on it. So if you go south twice, you’ll be able to click on “center” in the Northern End room description and also in the Southern End room description. But if you type “center” in, what should the game do? It seems intuitive that it should go to the most recently printed “center,” but that’s a bit hard to work out. (We can’t just repeat through the list backwards, because we don’t really want to add a link to the list when it’s truly redundant – if you go back to Northern End we don’t want to add those links to the list again. That really would be prohibitive in system resources, I think.)

Maybe I could set flags to denote whether a link was the most recently printed link corresponding to the same link text (so when you go to the Southern End, the “center/north” link gets flagged as the most recently printed link for “center,” and when you go to the Northern End, the “center/south” link gets flagged). That might be doable.

I also had something to make the text that you click on get echoed to the command line instead of the command it translates to, which gets complicated with this business. Maybe I’ll take another whack at it soon, but right now it’s a bit too complicated for me to deal with.

(But if you can avoid having the same text linking to different commands, and you don’t mind having the command text rather than the link text echoed to the command line, then I think the solution in my previous post is still OK.)

I’m not sure if you’d want to assume directions here. Wouldn’t it be more appropriate to link some phrase to a command?

The main hallway is a room. "The [link]bathroom[command]go east[/link] is thankfully right here off the main hallway." Understand "bathroom" as east when location is the main hallway.

It’s entirely possible an author may want ‘go east’ to be ‘examine bathroom’.

David C.
www.textfyre.com

Inline Hyperlinks does link the phrase to a command. When you click on a link it just puts the phrase after the “as” on the command line, which then gets parsed normally. So “e” and “east” and “go east” would all get put on the command line and then parsed into the action of going east.