Hyperlink Issues

DavyB
19 Dec 2018, 20:01I've turned up a few issues in allowing game players to switch hyperlinks on and off dynamically during game play. Below is test code to illustrate the problems. Hyperlinks have been selected under the Display game tab. They can be switched switched off with LINKS OFF and back on with LINKS ON. They are on initially.
Issue 1: Links are shown in a disambiguation menu when links are supposedly 'off'? (try x bin)
Issue 2: If hyperlinks are NOT selected under the game Display tab, they still appear in a disambiguation menu.
Issue 3: Again with hyperlinks NOT selected, they are still shown in the following text: You are in a {command:l:room}. Typing LINKS OFF appears to clear the link but on typing LOOK it reappears!
Issue 4: While experimenting, I'm repeatedly told that the game has been modified outside Quest, with an invitation to reload?
Thoughts?
<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Link Test">
<gameid>7bc55f56-daae-4ab6-88ff-98fc07ec4344</gameid>
<version>1.0</version>
<firstpublished>2018</firstpublished>
<enablehyperlinks />
<attr name="autodescription_youcango" type="int">0</attr>
<attr name="autodescription_description" type="int">1</attr>
<attr name="autodescription_youarein" type="int">0</attr>
<attr name="link_status">on</attr>
<feature_advancedscripts />
<inituserinterface type="script"><![CDATA[
JS.eval ("if (typeof(linksEnabled)=='undefined'){var linksEnabled = true;} function updateCommandLinks(data) { $('.commandlink').each(function (index, e) { var $e = $(e); if (!$(e).data('deactivated')) { var elementid = $e.data('elementid'); var available = $.inArray(elementid, data) > -1 || elementid.length == 0; if (available) { if (linksEnabled) {$e.removeClass('disabled');} } else { $e.addClass('disabled'); } } });$('.cmdlink').each(function(){ if (!linksEnabled) { $(this).addClass('disabled'); }});};")
SetHyperlinkStatus (game.link_status)
]]></inituserinterface>
<underlinehyperlinks />
</game>
<object name="room">
<inherit name="editor_room" />
<isroom />
<description>You are in a {command:l:room}.</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<object name="bread bin">
<inherit name="editor_object" />
</object>
<object name="has bin">
<inherit name="editor_object" />
</object>
</object>
<command name="links">
<pattern>links #text#</pattern>
<script>
SetHyperlinkStatus (text)
</script>
</command>
<function name="SetHyperlinkStatus" parameters="setting">
if (setting = "on") {
bool = "true"
}
else {
bool = "false"
}
JS.eval ("var linksEnabled = "+bool+";")
if (bool = "false") {
game.suppresshyperlinks = true
game.link_status = "off"
JS.eval ("$('.cmdlink,.commandlink').each(function(){$(this).addClass('disabled');});")
}
else {
game.suppresshyperlinks = false
game.link_status = "on"
}
</function>
</asl>
mrangel
19 Dec 2018, 20:56As far as I'm aware, the "enable hyperlinks" option in Quest controls whether GetDisplayName(object)
, {object:objectname}
and the core descriptions system generate links. It doesn't affect menus, or any command links you explicitly add to the text.
If you want to disable all links, you could use some javascript to modify the addText function so that it disables all links as they're printed:
$(function () {
var realAddText = addText;
turnHyperlinksOff = function () {
$('.cmdlink,.commandlink').addClass('disabled');
addText = function (text) {
text = $(text);
text.find('.cmdlink,.commandlink').addClass('disabled');
realAddText (text);
};
};
turnHyperlinksOff = function () {
addText = realAddText;
};
});
(then activated using JS.turnHyperlinksOff()
and JS.turnHyperlinksOn()
from Quest)

DavyB
20 Dec 2018, 09:52Thanks mrangel, I assume this should replace the code K.V. gave me to handle hyperlinks?
I've been avoiding JavaScript and the documentation I've found does not spell out the details clearly enough for me. What is the best way to include this function in a game?
I found that K.V.'s code covers most cases, though a couple of other oddities have turned up that I have still to explore. I'm hoping they will go away when I try out your code!