Howdy, Stranger!

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

Setting Variables

I'm new to TWINE and have been writing a story for the past month. I've read through several tutorials as well as some of the information on the wiki. However, I'm having trouble piecing it all together to solve my problem.

I want to make one choice in my story set a variable that will be referenced later. Here's an example:

"You are leaving the house, but you realize you forgot something. You rush back to in to retrieve your...

Choice 1) knife
Choice 2) lucky rabbit's foot"

Choosing the knife or the rabbit's foot will set variable $item to "knife" or "foot", but both choices should then proceed to the same passage next. How do I actually script that? I can imagine how to do it by creating new passages for choosing the knife or the rabbit's foot, but I would rather not create an extra passage since it seems unnecessary. Ideally, the flow would look like this:

(Passage 1) Leaving House (choose knife or rabbit's foot) ---> (Passage 2) On the Road

I hope I'm explaining this well. Can someone offer me some insight?

Comments

  • Hi!

    I think the easiest way to do this would be to use 'setter links'. These are links that set variables when you click them as well as moving you to a new passage. You can read more here : http://twinery.org/wiki/link#setting_variables_with_setter-links

    Essentially, to use them in your example, you'd do this:

    You are leaving the house, but you realize you forgot something. You rush back in to retrieve your...

    [[Knife|On the Road][$item = "knife"]]
    [[Lucky Rabbit's Foot|On the Road][$item = "rabbits foot"]]
    Hope this helps!
  • You can set variables within the choice, but point both to the same passage.

    [[displayed text|title of passage][$variable = expression]]

    [[Choose Knife|On the Road][$item = knife]]
    [[Choose Foot|On the Road][$item = foot]]
  • That is exactly what I had in mind. Thanks for both of your help.
Sign In or Register to comment.