Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Passage name from player input?

Hi everyone and a happy new year!

I'm new on the forum and I have a question that has me stumped, even though it seems to me like it must have a trivial solution... any help would be greatly appreciated!!  :)

I want to link to a passage name from player input. I get as far as reading in a variable with textinput, but I can't seem to be able to put anything like $variablename in a passage link (the [[]]s). Is this by design or am I missing something?

Example usage case: the player enters a number and the story jumps to a passage named after that number. (Like entering a combination for a safe lock.)

I use twee under Linux and would prefer not to use a GUI :) I'm also fine with ugly workarounds.

Comments

  • ...OK, I got it working with Taz's script (all the way down, the last one): https://groups.google.com/forum/#!topic/tweecode/9OggpvgERWA I'm not sure if I should keep this thread?
  • This isn't gonna be useful to you at this point, but in case anyone else has the same problem, but what I've always done in situations like that (when using twee) is:
    <<set $passage = "foo">>
    <<print "[[" + "link text" + "|" + $passage + "]]">>
    Which, surprisingly, actually works -- the print macro is expanded and then the link is evaluated, so you end up with a link to whatever passage is in $passage.
  • If you were using Twine 1.4 I'd recommend [[link text|$passage name]], but since not, well...
  • Hmmm, I ran into trouble - the back button functionality breaks with Taz's script, so I think I'll try xax's solution a bit later and let you know how it went :)

    Thank you everyone for the replies!! It's also good to know there is a solution in Twine 1.4 even if I'm not using it :)
  • I discovered a somewhat easy way, I don't believe anyone listed it yet though. So for example, in my story, I had the player input his name, then all conversations would have the typed in name. Here it is:
    I used the variable $name and also a pop up text box

    <<set $name = [[prompt("What's your name?","Name")]]>>
    "What's your name?" is the question on the box, "Name" is default text in the box. To use the name, just use <<print $name>> wherever you need it. This could also work with links. You can tailor it to passages/page numbers:

    <<set $pageNumber = [[prompt("What page?","Page Number")]]
    Followed by an <<if>> statement.
    <<if $pageNumber eq "2">>[[Page 2]]
    <<else if $pageNumber eq"7">>[[Page 7]]
    <<endif>>
    I'm completely new to Twine and basic coding, it took me a bit, but I got this. Idk if this helps you, but its useful for anyone else that may need it, there could be a more efficient way, but this was the easiest way I found without needing to make a Stylesheet passage. Any other type of coding is completely foreign to me, so I tried to find the simplest way. If you even see this, hope it's of use to you  :)


  • What if you want to use a variable string for the link text? is that possible in Twine?
  • Yeah, it should be. It doesn't seem like variables are expanded inside the link text, (at least in 1.4, which I'm still using,) but you can use the code I pasted above, with a slight tweak:

    <<set $passage = "foo">>
    <<set $link_text = "whatever">>
    <<print "[[" + $link_text + "|" + $passage + "]]">>
    which will make a link with a name of whatever the contents of $link_text are, to the passage of whatever $passage is. if you have a fixed passage, you can change that to

    <<set $link_text = "whatever">>
    <<print "[[" + $link_text + "|passage name here]]">>
  • Dazakiwi38 wrote:

    What if you want to use a variable string for the link text? is that possible in Twine?

    As it turns out, you can just do this:

    [[<<$link_text>>|$passage]]
    Yes, unbeknownst even to me, macros are permitted to run inside the text of links.
Sign In or Register to comment.