Emshort's basic hyperlinks - but built at runtime

Using Emily Short’s basic hyperlinks extension, I can do stuff like list the available topics of conversation, and have every topic be a hyperlink that inserts the command ‘ask soandso about topic’. The problem is that Glulx seems to only support setting a link using an id number; therefore, I would need to create a table that assigned a unique id to every imaginable combination of soandso and topic; and then I would need to figure out that id when listing the topics.

Any ideas how I might build the text of the replacement command at runtime, while listing topics?

I suspect you would do better with Inline Hyperlinks, which will deal with all the hyperlink management for you.

You’d end up using something like this, I think:

"[link][topic][as]ask [the current interlocutor] about [topic][end link]";

Well, one method is as follows:

  1. Number NPCs from 0.
  2. Number posssible topics from 0 to (say) 999.
  3. Define the number of “ask NPC about TOPIC” as 1000*(npc number) + (topic number).

Another method is:

  1. Get an upper bound on the number of NPC/topic combinations you’ll need.
  2. Create a table with one column being indexed text.
  3. Whenever you have to print a link, look through the table to see if the entry is already there.
    3a) If the entry is, select the number of the corresponding row.
    3b) If the entry isn’t, add a new entry with the corresponding text, and select the number of the new row.

I came up with a solution using a circular buffer stored in a table.

gist.github.com/Blecki/5792366

But I think I’ll go with Erik Temple’s extension. If I can make mine work with his method of declaring links, I think it would be perfect, as the circular buffer avoids having to store and traverse a huge list of commands.

Al right, I’ve got a solution that uses the syntax of Erik Temple’s extension, but doesn’t have to traverse a list of commands every time it says a link (Which could happen dozens of times outputting the result of a single command). It has it’s own limitation: If the table isn’t large enough, links at the top of the window will be overwritten by links generated at the bottom. You need a large table, however, it will still be smaller than a list of every command that could possibly be typed that Erik Temple’s extension is likely to produce.

gist.github.com/Blecki/5792481

I should point out that I plan on blanketing the entire game in this to make it easily playable on touch screen devices like the ipad. The conversation stuff was just the first part I encountered where writing the commands out in the code wasn’t feasible.