Howdy, Stranger!

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

Setter links in Twine 2

As I understand it setter links as they existed in 1.xx are no longer a feature in 2.0, so I'm wondering if there's another way to achieve the same purpose.

Basically, I want clicking links to modify variables.

Comments

  • (edited based on L reply below)
    (note: The following examples are written using TWEE notation, lines starting with a double colon "::" represent a new passage with the text following the passage title.)

    As L states, you can use a combination of the (link:), (set:) and (goto:) macros to achieve what you want.:

    :: Setter Link
    Assign the `$var` a default value of: (set: $var to 1)$var

    (link:"Text that appears and acts like a link with a setter that changes the `$var` variable to 2")[(set: $var to 2)(goto: "Links Target")]

    :: Link Target
    The `$var` equals $var
    or you can use a hook and the (click:), (set:) and (goto:) macros to also do the same.

    :: Setter Link
    Assign the `$var` a default value of: (set: $var to 1)$var

    [Text that appears and acts like a link with a setter that changes the `$var` variable to 2]<setter-link|
    (click: ?setter-link)[(set: $var to 2)(goto: "Link Target")]

    :: Link Target
    The `$var` equals $var
  • For most uses (where the link text doesn't contain too much formatting) the recommended idiom is actually
    (link:"Link text")[(goto:"Passage Name")]
    As an aside: I prefer this to Twine 1's setter link syntax because it's an intuitive combination of simple elements. Although, it currently has the downside that (goto:) isn't recognised by the passage map in terms of creating an arrow.
  • L wrote:

    For most uses (where the link text doesn't contain too much formatting) the recommended idiom is actually
    (link:"Link text")[(goto:"Passage Name")]
    As an aside: I prefer this to Twine 1's setter link syntax because it's an intuitive combination of simple elements. Although, it currently has the downside that (goto:) isn't recognised by the passage map in terms of creating an arrow.


    I am assuming you meant the following, because @letominor was asking on how to do a setter type link.
    (link:"Link text")[(set: $var to 2)(goto:"Passage Name")]
  • greyelf wrote:

    L wrote:

    For most uses (where the link text doesn't contain too much formatting) the recommended idiom is actually
    (link:"Link text")[(goto:"Passage Name")]
    As an aside: I prefer this to Twine 1's setter link syntax because it's an intuitive combination of simple elements. Although, it currently has the downside that (goto:) isn't recognised by the passage map in terms of creating an arrow.


    I am assuming you meant the following, because @letominor was asking on how to do a setter type link.
    (link:"Link text")[(set: $var to 2)(goto:"Passage Name")]


    Thanks! That's exactly what I needed.
  • I tested this code verbatim but didn't produce the desired results.  :-\


    The $var value did not change.


    greyelf wrote:

    (edited based on L reply below)

    :: Setter Link
    Assign the `$var` a default value of: (set: $var to 1)$var

    [Text that appears and acts like a link with a setter that changes the `$var` variable to 2]<setter-link|
    (click: ?setter-link)[(set: $var to 2)(goto: "Link Target")]

    :: Link Target
    The `$var` equals $var
  • [quote author=writer_ link=topic=2103.msg5979#msg5979 date=1419003364]
    I tested this code verbatim but didn't produce the desired results.  :-\


    You're doing it wrong.  Per greyelf: (emphasis mine)
    greyelf wrote:

    (note: The following examples are written using TWEE notation, lines starting with a double colon "::" represent a new passage with the text following the passage title.)


    In other words, you should have two passages.  One named `Setter Link`, with the text:

    Assign the `$var` a default value of: (set: $var to 1)$var

    [Text that appears and acts like a link with a setter that changes the `$var` variable to 2]<setter-link|
    (click: ?setter-link)[(set: $var to 2)(goto: "Link Target")]
    And the other named `Link Target`, with the text:

    The `$var` equals $var

    Additionally, you seem to have a misunderstanding about what the undo/redo buttons actually do.  The undo/redo buttons traverse the state history.  Essentially, undo goes back in time, while redo returns you to the present.  You cannot go back to a previous state and expect to see results from the present.
  • @TheMadeExile

    Thank you for your reply. As you can obviously see, I'm new here and the docs are a bit thin on Twine 2.

    I like the going back in time reference... only if we could, eh? :)

    But I was aiming at a click count into a 'room' for example.

    e.g.
    You have been in this room $var times!
    or
    You have looked at this item $var times!

    Can you share with me code that does that?

    thank you
  • I'm not exactly well versed in Harlowe, but these examples might suffice.

    Start passage:

    {
    (if: $jakeVisits is 0)[(link-goto: "Visit Jake", "Jake's Place")]
    (else:)[(link-goto: "Visit Jake (again)", "Jake's Place")]
    }
    Jake&#039;s Place passage:

    {
    (set: $jakeVisits to it + 1)
    "Hello. You've
    (if: $jakeVisits is 1)[never been here]
    (else:)[been here (print: $jakeVisits - 1) time(if: $jakeVisits > 2)[s]]
    before," Jake says with a smile as he flicks a bead on his abacus.
    }

    M.E.L. computes your previous visit count as (count: (history:), "Jake's Place"). Isn't that amazing!

    [[Return to the start|Start]] (do not use the `Undo` button here)

    The Jake&#039;s Place passage shows two different ways of counting passage visits.  One is a simple incrementing $variable, while the other uses (history:).
  • Many many thanks!
  • How can I do this when I want to setup a choice?  In others words, first link sets the $var to 2 and second link sets the $var to 3?
  • All what setter links provide us we can make adding more passages. I like them, because I can make a single passage behave in many ways to use less passages.

    Sadly, Twine Editor can't read setter links manually built with goto to draw the arrows linking passages, so a workaround is necessary, hiding a traditional link in a  hook attached to a false variable.
    (set: $impossible to 0)
    (if: $impossible)[ [[Link Target]] ]
    There are plans to add support of link and goto macros in the editor?

    UPDATE:
    A short form using 0 directly:
    (if: 0)[ [[Link Target]] ]
  • Currently the Story/Passage Map supports drawing arrows for the types of links that are common to the all the different story formats.

    There is currently no way for a specific story format to define what other types of links should also result in an arrow being drawn. As to when/if this will change only Chris and Leon would know that answer.
  • Hello
    I found how to describe a setter link in Twine 2.0.10:
    [Link_Text[(set: $variable to value)|Passage_Title !]]
    e.g: [Yes[(set: $score to it + 1))|Success !]]
  • almerxsese wrote: »
    e.g: [Yes[(set: $score to it + 1))|Success !]]
    I tested your example in Twine 2.0.10 using Harlowe 1.2.1 and it did not work, nor did I expect it to because a markup link needs to start and end with double square brackets.

    eg. It outputted: [Yes[)|Success !]]

    Did you type out your example incorrectly?
Sign In or Register to comment.