Help with individual Hyperlinks for Items and Things

Hey Everyone!

I am looking for some help regarding hyperlinks, as i have little to no idea about how to pull something like this of. I am currently making an RPG like game, and i want to start using hyperlinks to make some task easier for the player in the long run.

So the general idea, is to have a hyperlink be displayed before printing the name of an item lying on the ground for an example, the item would be printed like this:

[Take] - an Iron Sword

The part in square brackets being clickable and then taking the item.

The code i have made for it so far looks like this:

Before printing the name of an item (called printed_item):
	if printed_item is on-stage:
		say "[set link 15][bracket]Take[close bracket][end link] - ".

Link 15 referencing the take action solely with a give noun. The idea is to avoid the hassle of making a unique hyperlink for every item that exists.
Here i tried to mess around with something like a rule for when the player tries to take something without supplying a noun, but i ran short of ways to actually do something like that.

Rule for supplying a missing noun while taking:
	now the noun is ???.

So is there anyone out there with an idea about how to do something like that? Is there a way to do it at all? Maybe with an extension?

Thanks for the help!

First off—which hyperlink extension are you using? Inline Hyperlinks by Erik Temple allows you to specify the command directly instead of using the numbers:

say "[link](TAKE)[as]take [the item described][end link]"

I’ve only been using Basic Hyperlinks by Emily Short. I will try to use Inline Hyperlinks and do something like you just did! Thanks :slight_smile:

Okay so i tried doing something like what you described in a test game, like the one provided with Erik Temples version of Inline Hyperlinks and your modified version of Inline Hyperlinks. Both gives me a stack overflow fatal error. The test story i used was this one:

Include Inline Hyperlinks by Erik Temple.

The printed name of a room is "Maze". The description of a room is usually "A maze of twisty little passages, all alike. Exits: [exits]".
To say exits:
	let count be the number of adjacent rooms;
	if count is greater than 0:
		repeat with destination running through adjacent rooms:
			let the way be the best route from the location to the destination, using even locked doors;
			let dir be indexed text;
			let dir be "[way]";
			let dir be "[dir]";
			say "[link][way][as]go [dir][end link]";
			let count be count minus 1;
			if count > 0:
				say ", ";
		say ". ".
		
R01 is a room. R02 is north of R01. R03 is east of R01. R04 is north of R02 and northwest of R03. R05 is northeast of R02. R06 is north of R05. R07 is west of R06. R08 is southwest of R04 and northwest of R02. R09 is east of R06. R10 is northeast of R06. R11 is east of R10. R12 is southeast of R09. R13 is south of R12. R14 is northeast of R12. R14 is southeast of R11. R15 is up from R03. R16 is east of R15. R17 is north of R16. R18 is down from R17. The description of R18 is "A maze of twisty little passages, all alike. A breeze blows from the northeast. Exits: [exits]".

Exit is northeast of R18. Exit is outside from R18. The printed name of Exit is "Outside". "You emerge into sunlight." Southwest from Exit is nowhere. Inside from Exit is nowhere.

A hat is a kind of thing.
In R01 is a hat.

Before printing the name of a hat (called printed_item):
	say "[link](TAKE)[as]take [the item described][end link]".

The story works if i remove:

A hat is a kind of thing.
In R01 is a hat.

Before printing the name of a hat (called printed_item):
	say "[link](TAKE)[as]take [the item described][end link]".

Otherwise i get it:
Erik Temples Inline Hyperlinks Error: Glulxe fatal error: Stack overflow in function call.
Daniel Stelzer Inline Hyperlinks Error: Glulxe fatal error: Stack overflow in callstub.

I tried to play around with it afterwards, and it seems that when i change [the item described] with [printed_item] it sort of works but spits out this:

You can see a take (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hattake (TAKE)hat here.

What am i doing wrong?

Your ‘before printing the name of a hat’ rule tries printing the name of the hat (because it uses [the item described] inside of a say phrase), which invokes your before rule, which tries printing the name of the hat, which invokes your before rule … until the stack overflows.

Try this instead:

link-printing is initially false.

Rule for printing the name of a hat when link-printing is false:
	now link-printing is true;
	say "[link][item described][as]take [item described][end link]";
	now link-printing is false.

Cool that made it work, thanks!

Got another question though. Is there any way to make Inline Hyperlinks compatible with Emily Shorts Basic Hyperlinks?

The conflicting code is this:
Basic Hyperlinks:

A clicking hyperlink rule (this is the default command replacement by hyperlinks rule):  
	repeat through the Table of Hyperlink Glulx Replacement Commands:
		if the current link number is linknum entry:
			now the glulx replacement command is replacement entry;
			rule succeeds;
	now glulx replacement command is "".

Inline Hyperlinks:

A hyperlink processing rule (this is the default command replacement by hyperlinks rule):  
	now the glulx replacement command is entry (current hyperlink ID) of the hyperlink list;
	rule succeeds.

Thanks!

*Edit: I am reading through Inline Hyperlinks trying to understand it, and it also says to replace something if i am using Flexible Windows, which i am, what exactly is it i am supposed to replace?

The Flexible Windows replacement should happen automatically. When there are sections labelled “(for use with Flexible Windows…)” or “(in place of [something] in [something])” and such, those are like #ifdefs. Those sections will automatically be included or removed depending on other extensions you’ve included.

Unfortunately I don’t think Inline Hyperlinks and Basic Hyperlinks can be used together. They’re fundamentally both looking for the same inputs, and trying to do different things with them.

Okay, well maybe you can help me transition from basic hyperlinks to inline hyperlinks. The thing is i am already quite far into my project, and the way i am using basic hyperlinks, is for printing possible paths to go to. I however want already visited rooms paths to be displayed upon visit.

The current code looks like this:


To say to (place - a room): if the place is visited, say " ([place])".

The Minoran Alley is a room. The Minoran Alley is southeast of the Minoran Smithworks, northwest of the Silverwhite Marketplace and northeast of the Westhall Square. "You enter a crowded alley, beggars and commonfolk on every corner. Roads and alleyways lead in all directions.[paragraph break]You can go  
 [set link 12]North-West[end link][to the Minoran Smithworks],
 [set link 14]North-East[end link][to the Minoran Dockyards],
 [set link 11]South-West[end link][to the Westhall Square],
 [set link 13]South-East[end link][to the Silverwhite Marketplace] and
 [set link 3]East[end link][to the Silverwhite Alley].

When i use the example provided in the Maze example:

To say all exits:
	let count be the number of adjacent rooms;
	if count is greater than 0:
		repeat with destination running through adjacent rooms:
			let the way be the best route from the location to the destination, using even locked doors;
			let dir be indexed text;
			let dir be "[Way]";
			let dir be "[Dir]";
			say "[link][Way][as][Dir][end link]";
			let count be count minus 1;
			if count > 0:
				say ", ";
		say ". ".

I only get the possible directions. I tried to implement something similar like i am using now, but that gave me run-time errors and such, probably because i was phrasing things incorrectly.

Edit: I actually managed to do it myself, for others in the future, you can use this:

To say all exits:
	let count be the number of adjacent rooms;
	if count is greater than 0:
		repeat with destination running through adjacent rooms:
			let the way be the best route from the location to the destination, using even locked doors;
			let dir be indexed text;
			let dir be "[Way]";
			let dir be "[Dir]";
			say "[link][Way][as][Dir][end link]";
			if destination is visited:
				say " ([destination])";
			let count be count minus 1;
			if count is 1:
				say " and ";
			else if count > 1:
				say ", ";
		say ". ".

Just one last question, how do i get north and such to display with a capital letter like “North” instead of “north”?

Due to changes in Inform, you no longer need all the “let dir be…” things (you can just say “[link][Way][end link]”).

If you want it to be capitalized, you can do this.

let the dir be "[way]" in title case; say "[link][dir][end link]";
“Title case” means capitalizing the first letter of each word.

Nice thanks!

I have however run into a new problem (i know).

It seems like its not compatible with Flexible Windows, which i didn’t test before now in practice, as i am implementing it into my game now.

I am using the version from github here: github.com/i7/extensions

and i am getting this error also when trying to use the version by you:

In Chapter 2 - Replace Flexible Windows hyperlink handling if necessary (for use with Flexible Windows by Jon Ingold), Section - Code for selecting the replacement command (replaces Section - Selecting the replacement command in Flexible Windows by Jon Ingold) in the extension Inline Hyperlinks by Erik Temple:

Problem. You wrote 'A hyperlink processing rule (this is the default command replacement by hyperlinks rule)'  : but the punctuation here ':' makes me think this should be a definition of a phrase and it doesn't begin as it should, with either 'To' (e.g. 'To flood the riverplain:'), 'Definition:', a name for a rule (e.g. 'This is the devilishly cunning rule:'), 'At' plus a time (e.g. 'At 11:12 PM:' or 'At the time when the clock chimes') or the name of a rulebook, possibly followed by some description of the action or value to apply to (e.g. 'Instead of taking something:' or 'Every turn:').

 See the manual: 19.3 > 19.3. New rules

It seems like the name for the rule is not accepted?

It sounds like the hyperlink processing rulebook isn’t understood. I’ll look into it.

Okay, i assume you get the same error on your end?

Thank you for the help though! :smiley:

It looks like that rulebook has been removed and replaced with the “processing hyperlinks” activity, so changing it to a “for processing hyperlinks” rule is probably the best option.

Okay so i tried this

For processing hyperlinks rule (this is the default command replacement by hyperlinks rule):  
	now the glulx replacement command is entry (current hyperlink ID) of the hyperlink list;
	rule succeeds.

which gives me this error

In Chapter 2 - Replace Flexible Windows hyperlink handling if necessary (for use with Flexible Windows by Jon Ingold), Section - Code for selecting the replacement command (replaces Section - Selecting the replacement command in Flexible Windows by Jon Ingold) in the extension Inline Hyperlinks by Daniel Stelzer:

Problem. You wrote 'now the glulx replacement command is entry (current hyperlink ID) of the hyperlink list'  : but this is a phrase which I don't recognise, possibly because it is one you meant to define but never got round to, or because the wording is wrong (see the Phrasebook section of the Index to check). Alternatively, it may be that the text immediately previous to this was a definition whose ending, normally a full stop, is missing?

I was trying to match this phrase:

 now (glulx replacement command is entry ( current hyperlink id ) of the hyperlink list - a phrase) 

But I didn't recognise 'glulx replacement command is entry ( current hyperlink id ) of the hyperlink list'.

Not sure if i did it the right way, not too sharp with inform

That…is interesting. And I’m not sure what it means either, unfortunately. “The hyperlink list” is a list defined in that extension, “entry (number) of (list)” is a built-in phrase, “the glulx replacement command” is defined in Glulx Entry Points by Emily Short, and “now (variable) is (value)” is built-in syntax…so likely the problem is somewhere else, and Inform is misreporting it. :confused:

Okay so i’ve been trying out a few things. And since the problems only arise when used together with Flexible Windows i decided to look into Flexible Windows, and i found something i don’t understand. In the Inline Hyperlinks extension its says this.

Section - Code for selecting the replacement command (replaces Section - Selecting the replacement command in Flexible Windows by Jon Ingold)

A hyperlink processing rule (this is the default command replacement by hyperlinks rule):  
	now the glulx replacement command is entry (current hyperlink ID) of the hyperlink list;
	rule succeeds.

It says replaces Section - Selecting the replacement command in Flexible Windows by Jon Ingold. However, Flexible Windows doesn’t have a section like that, maybe that is the problem? The hyperlink stuff in Flexible Windows is all contained in a chapter like this:

Part - Input events

Chapter - Hyperlinks

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

To say end link:
	(- if ( glk_gestalt( gestalt_Hyperlinks, 0 ) ) { glk_set_hyperlink( 0 ); } -).

Processing hyperlinks for something is an activity on g-windows.
The processing hyperlinks activity has a number called the hyperlink ID.

After constructing a textual g-window (called win) (this is the request hyperlink events rule):
	if glk hyperlinks are supported:
		call glk_request_hyperlink_event for win;

A glulx input handling rule for a hyperlink-event (this is the default hyperlink handling rule):
	carry out the processing hyperlinks activity with the glk event window;

Before processing hyperlinks (this is the prepare for processing hyperlinks rule):
	now the hyperlink ID is the glk event val1;

Last for processing hyperlinks (this is the default hyperlink command replacement rule):
	repeat through the Table of Glulx Hyperlink Replacement Commands:
		if the hyperlink ID is link ID entry:
			now the glulx replacement command is replacement entry;
			rule succeeds;
	now the glulx replacement command is "";

Table of Glulx Hyperlink Replacement Commands
link ID (number)	replacement (text)
--

After processing hyperlinks for a g-window (called win) (this is the request hyperlink events again rule):
	call glk_request_hyperlink_event for win;

So maybe it’s trying to replace the wrong kind of rule?

Edit: I updated Flexible Windows as i had an older version. The version i have now doesn’t even have that part with hyperlinks. It actually has NOTHING at all regarding code with hyperlinks, yet the problem still persists. I read the changelog made, and it says this;

  • The hyperlink processing rules have been turned into the processing hyperlinks activity.

could this have anything to do with it?

Okay so i’ve been playing around for awhile now, trying to make this work and searching the interwebs. I found this guy called Nuku Valente, whom have several modified versions of extensions uploaded to github here: github.com/Nuku/Flexible-Survival

His version of Flexible Windows contains a bit of code concerning hyperlinks, an entire chapter in fact:

Section - Hyperlink event handling

A glulx hyperlink rule (this is the default hyperlink handling rule):
	[unless the status window is the hyperlink source:
		now the current hyperlink window is the window with the reference of the window in which the event occurred;]
	[now the current hyperlink ID is the link number of the selected hyperlink;]
	unless the current hyperlink ID is 0:
		[cancel glulx hyperlink request in the current hyperlink window;[just to be safe]]
		follow the hyperlink processing rules;
	if the status window is the hyperlink source:
		request glulx hyperlink event in status window;
	[otherwise:
		request glulx hyperlink event in the current hyperlink window.]

To request glulx hyperlink event in (win - a g-window):
	(-  if (glk_gestalt(gestalt_Hyperlinks, 0)) glk_request_hyperlink_event({win}.ref_number); -)

To cancel glulx hyperlink request in (win - a g-window):
	(-  if (glk_gestalt(gestalt_Hyperlinks, 0)) glk_cancel_hyperlink_event({win}.ref_number); -)

To request glulx hyperlink event in the/-- status window:
	(-  if (glk_gestalt(gestalt_Hyperlinks, 0)  && gg_statuswin) glk_request_hyperlink_event(gg_statuswin); -)
	
To cancel glulx hyperlink event in the/-- status window:
	(-  if (glk_gestalt(gestalt_Hyperlinks, 0) && gg_statuswin) glk_cancel_hyperlink_event(gg_statuswin); -)

To decide whether the status window is the hyperlink source:
	(- (gg_event-->1==gg_statuswin) -)

[To decide which g-window is the window with (N - a number):
	repeat with item running through g-windows:
		if N is the ref-number of item:
			decide on item;
	decide on main-window.]


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

To say end link:
	(-  if (glk_gestalt(gestalt_Hyperlinks, 0)) glk_set_hyperlink(0); -)


Section - Processing hyperlinks

The hyperlink processing rules are a rulebook.

The current hyperlink ID is a number that varies.


Section - Selecting the replacement command

The last hyperlink processing rule (this is the default command replacement by hyperlink rule):  
	repeat through the Table of Glulx Hyperlink Replacement Commands:
		if the current hyperlink ID is link ID entry:
			now the glulx replacement command is replacement entry;
			rule succeeds;
	now glulx replacement command is "".


Table of Glulx Hyperlink Replacement Commands
link ID	replacement
a number	some text

I took that part and copy pasted it into my version of Flexible Windows, and that actually solved the previous error. I however received new errors regarding this new chunk of code i just copypasted in. I outcommented the bits of code, and it kinda works now (or atleast succesfully compiles). It doesn’t give me any errors, and it display the hyperlinks, they are however Unclickable.

I don’t know if this helps maybe?

Just a little history here, in case it helps: I haven’t updated Inline Hyperlinks in a long time (two versions of Inform, perhaps? The last version I did used indexed text, which is no longer a thing. Someone else may have updated it though). Additionally, since the last update of Inline Hyperlinks, Dannii has taken over maintenance of Flexible Windows and made many, many changes to it–including removing all of the hyperlink-related code a few months ago. In addition, I think that Dannii may also have made changes to Glulx Entry Points, on which both extensions depend. So it likely won’t be any easy thing to sort through by version to get this working.

My recommendation would be that you start with the newest possible versions of each of these extensions and essentially rewrite Inline Hyperlinks to work with the newest FW and GEP.

But if Dannii has removed all the hyperlink-related code, then what is the incompatibility about? I have been sifting through some older Flexible Windows code, and that has hyperlink code, and it makes sense for me to have hyperlinks in your windows, so why was it removed and why would it cause compatibility issues if flexible windows no longer has anything to do with hyperlinks?

I can’t seem to update glulx entry points for some reason, maybe because it’s essential? i am using 6L38, should i update? Last time i tried my project received all kinds of incompatibilities, and it seemed like most extensions we’re for that version only anyway, so i didn’t.

Inline Hyperlinks still expects Flexible Windows to have the old hyperlink-related code, and refers to it, and so Inform gets confused when it’s not there.

I forget exactly why Dannii said he removed it (you can search for his explanation if you want, I think it might be on this forum somewhere) but I suspect he wanted to avoid compatibility problems in case the author wanted to use Flexible Windows with a different hyperlink extension.

If you’re not sure how to update/rewrite Inline Hyperlinks, as Erik suggested, you could maybe report an issue on Github saying that Inline Hyperlinks doesn’t work with the latest Flexible Windows, and some other people may be able to help. I can look at it later; I don’t know whether it’ll be within my ability to help though.