Howdy, Stranger!

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

making options disappear on a page after one is selected

Hi everyone! I'm pretty new to Twine and coding in general, so excuse me if this is a silly question.

I'm using Harlowe. Currently I'm trying to make it so when you click an option, the other choices presented vanish and leave you simply with the result of your choice. I've found ways to do that with links to other pages, but I want to stay on the page.

First, I set the initial value to false on a previous page:
(set: $hair to 'false')

Then I list my choices on the appropriate page:
(unless: $hair is 'brown' OR $hair is 'red' OR $hair is 'black')[(link: "her soft blonde hair.")[ Her hair was blonde. (set: $hair to 'blonde')]]
(unless: $hair is 'blonde' OR $hair is 'red' OR $hair is 'black')[(link: "her chestnut brown hair.")[ Her hair was brown.(set: $hair to 'brown')]]
(unless: $hair is 'brown' OR $hair is 'blonde' OR $hair is 'black')[(link: "her bright auburn hair.")[ Her hair was red. (set: $hair to 'red')]]
(unless: $hair is 'brown' OR $hair is 'red' OR $hair is 'blonde')[(link: "her thick black hair.")[ Her hair was black.(set: $hair to 'black')]]

I could select the options all right, but the other options wouldn't vanish like I wanted. I also tried:
(if: $hair is 'false' OR $hair is 'blonde')[(link: "her soft blonde hair.")[ Her hair was blonde. (set: $hair to 'blonde')]]
(if: $hair is 'false' OR $hair is 'brown')[(link: "her chestnut brown hair.")[ Her hair was brown.(set: $hair to 'brown')]]
(if: $hair is 'false' OR $hair is 'red')[(link: "her bright auburn hair.")[ Her hair was red. (set: $hair to 'red')]]
(if: $hair is 'false' OR $hair is 'black')[(link: "her thick black hair.")[ Her hair was black.(set: $hair to 'black')]]

With the same results. Does anyone have any suggestions? I know this is really simple, but I really can't get it to work.

Comments

  • edited November 2016
    In most cases conditional statements like your (unless: $hair is 'brown' OR $hair is 'red' OR $hair is 'black') or your (if: $hair is 'false' OR $hair is 'blonde') are only evaluated when the relevant passage is displayed to the reader, this means that by default those conditional statements will not be re-evaluated if the value of the variables they reference are changed via something like a link unless that link results in passage traversal (movement for one passage to another).

    There are a number of ways to solve your issue, one of the simpler is to use a named hook combined with a (replace: ) macro to update the relevant area of the page.

    1. Set the initial value of the $hair variable to an empty string sometime prior to the current passage, the most ideal place to do this is within your story's startup tagged passage.
    (set: $hair to '')
    

    2. Include code like the following example within the passage where they get to select their hair colour.
    (if: $hair is '')[
    |choice>[
    (link: "her soft blonde hair.")[
    	(set: $hair to 'blonde')
    	(replace: ?choice)[Her hair was blonde.]
    ]
    (link: "her chestnut brown hair.")[
    	(set: $hair to 'brown')
    	(replace: ?choice)[Her hair was brown.]
    ]
    (link: "her bright auburn hair.")[
    	(set: $hair to 'red')
    	(replace: ?choice)[Her hair was red.]
    ]
    (link: "her thick black hair.")[
    	(set: $hair to 'black')
    	(replace: ?choice)[Her hair was black.]
    ]
    ]
    ](else:)[Her hair was $hair]
    

    note: Thank you for including the name of your Story Format in your original question, it helps immensely although could you also include the version as well in the future.
    The reason for this is that the next release of Twine 2 will include two different versions of Harlowe and knowing the exact version will help anyone answering a question.
  • That fixed it- thank you! I figured it was something like that where it wouldn't reevaluate unless I told it to but I couldn't figure out how to do it. I'll include the version in the future :)
Sign In or Register to comment.