Howdy, Stranger!

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

Help With Variables.

Hello. I'm new to Twine and I've been using this resource to learn about different commands. http://twine2.neocities.org/ But, I'm not able to figure out how to set variables based on choices made by the player.


Say I give the player four speech options. I want to be able to have four different variations of another character's reply which are each based on the speech option chosen. So far, I've been able to do this by having four passages that are slightly different. But, this takes up tons of space. I'd prefer to have each speech option link to the same passage, but have four different hooks where only one is shown based on the player's choice of speech options.

I do know how to set variables, but only based on what pages are visited, and not on what choice are made.

Thank you.

Comments

  • In Twine 1 story formats as well as SugarCube there is a type of link know as a Setter Links that allows to assign/set variables when a user clicked on them, Harlowe currently does have this type of link.

    One way to simulate Setter Links in Harlowe is by using a link, set, and goto macro combo like the following:

    (link: "Option 1" )[(set: $var to "A")(goto: "Next Passage")]
    (link: "Option 2" )[(set: $var to "B")(goto: "Next Passage")]
    You can also simulate a Setter Link is by using a hook, click, set, and goto macro combo like the following:

    [Option 1]<link1|
    [Option 2]<link2|

    (click: ?link1)[(set: $var to "A")(goto: "Next Passage")]
    (click: ?link2)[(set: $var to "B")(goto: "Next Passage")]
    In the Next Passage passage you can selectively show text based on the value of the variable:

    (if: $var is "A")[The text to be shown if Option 1 was selected in previous passage.]
    (if: $var is "B")[The text to be shown if Option 2 was selected in previous passage.]
  • Thank you. Will this work in Twine 2 as well?
  • Thorston wrote:

    Thank you. Will this work in Twine 2 as well?

    Yes, the above code is for the Harlowe story format which is Twine 2 only.
  • Thank you so much. The first way seems much easier. Is there some kind of benefit I'm losing by going the easy route?

    And, just to be clear, I would literally write out "link", as opposed to writing something else that is the link? Then Option 1 and 2 would be the clickable options, right? That is, what the player sees on their screen.
  • Thorston wrote:

    Thank you so much. The first way seems much easier. Is there some kind of benefit I'm losing by going the easy route?

    No, I was just showing that there is more than one way to do what you wanted. Use the first method.

    [quote]
    And, just to be clear, I would literally write out "link", as opposed to writing something else that is the link? Then Option 1 and 2 would be the clickable options, right? That is, what the player sees on their screen.

    Yes, if you look at the Harlowe documentation (which is what you linked to in your original post) you will see that the (link:) macro takes one parameter. The parameter is the text that you want link to show.
  • Thanks again, Mr. Elf.

    I've tried this and I'm able to make it work, which makes my heart happy. However, the arrows showing the connection to the passage in the "goto" part don't appear. Is that normal? Is there a way to fix it? Is there a way  I can put in my own arrows to help me keep track?
  • Thorston wrote:

    Is that normal?
    Is there a way to fix it?
    Is there a way  I can put in my own arrows to help me keep track?

    Yes
    No  (well yes but if will take modifications to the application outside your control, see below)
    Not sure, but I don't believe so.

    The Twine 2 application currently only knows about things that are common to all story formats (such as markup links [[Passage Name]], etc), and there is currently no way for the Creator of a Story Format to influence things like syntax highlighting or what else is a link, which is why the Twine application does not know about the (link:) macro.

    BTW: Because the (if:) macros in my previous post are related (and mutually exclusive) you could use the (elseif:) macro in place of the second (if:)

    (if: $var is "A")[The text to be shown if Option 1 was selected in previous passage.]
    (elseif: $var is "B")[The text to be shown if Option 2 was selected in previous passage.]
Sign In or Register to comment.