tweecode / twine

UI for creating hypertext stories
http://twinery.org
657 stars 97 forks source link

Allow variables in links to passages #1

Closed factorypreset closed 11 years ago

factorypreset commented 12 years ago

Suggested by Strangelander (via email):

The only ability I think Twine absolutely needs to add is the ability to set a variable to a passage title and then go to the passage using the variable, something like:

<<set $nextPlace = "Basement stairs">>
[[<<$nextPlace>>]]
or
[[Go down|<<$nextPlace>>]]
and
<<if $monsterDead>><<display $nextPlace>><<endif>>
HarmlessTrouble commented 12 years ago

Philip Requested i take a look at this issue.

<<display $variable>> is easy enough

(and a solution has been recently offered from CodeDuck https://groups.google.com/forum/?fromgroups#!searchin/tweecode/%3C%3Cdisplay/tweecode/9OggpvgERWA/yjDdVNHuCDQJ)

while this is good to have, this isn't a true dynamic link.

Wikifier.formatters seems to match [[]] and <<>> in one pass. so to get something like say [[<<print $Passage>> |<<print $Passage>>]] to work all we would need to do pass the content of the internal link through the "macro"formatter in a line just before the Wikifier.createInternalLink is used inside the "prettyLink " formatter.

HarmlessTrouble commented 12 years ago

Here's a macro equivalent for generating dynamic links,

< < dynamiclink [passagename] [linktext]> >

macros.dynamiclink = {handler: function(a,b,c){ var d; try{d = eval(Wikifier.parse(c[0]));}catch(e){d=c[0];} if (c[1]){ var f; try{f = eval(Wikifier.parse(c[1]));} catch(e){f=c[1];} }else{e=c[0]} el=document.createElement("a"); el.className="internalLink"; el.href="javascript: void(0)"; el.onclick=function(){state.display(d,el)} el.innerHTML=d; if (f){el.innerHTML=f;} a.appendChild(el) }};

INext, 'll try to use this technique directly inside the "prettyLink" formatter.

HarmlessTrouble commented 11 years ago

using print macro technique to render dynamic links is imo sufficient to satisfy this functionality.

Any objections to closing this feature request?