Howdy, Stranger!

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

Is it possible to compile a list of answers at the end of the story?

I'm working on an idea in which the reader answers a series of yes/no questions that are compiled all together in a page at the end. For example:

Do you like Ice Cream?
Yes.

Do you Like Strawberry Ice Cream?
No.

At the end, the final page would say:
I like ice cream. I do not like strawberry ice cream.

What I'm planning is a vast series of questions, so I wouldn't be able to do it by creating some sets of linear stories as there would be too many possible outcomes at the end.

Is this possible? Is it possible to refer to other pages in coding etc?

Thanks

Comments

  • You need to state which Story Format you are using when you ask a question because answers can be different for each one.
    I am going to assume you are using Harlowe and that you are using Yes/No markup links to move the Reader from one question (passage) to another (passage).

    You can use the (set:) macro to assign the answer for each of your questions to story variables.

    eg. The first question passage would contain something like the following:
    Do you like Ice Cream?
    (link: "Yes")[
    	(set: $likesIcecream to true)
    	(goto: "Question 2")
    ]
    (link: "No")[
    	(set: $likesIcecream to false)
    	(goto: "Question 2")
    ]
    
    ... and the second question passage (Question 2):
    Do you Like Strawberry Ice Cream?
    (link: "Yes")[
    	(set: $likesStrawberry to true)
    	(goto: "Question 3")
    ]
    (link: "No")[
    	(set: $likesStrawberry to false)
    	(goto: "Question 3")
    ]
    

    You can then use the (if: ) macro and the (else: ) macro to check the values of the variables in the final passage:
    (if: $likesIcecream)[I like ice cream.](else:)[I do not like ice cream.]
    
    (if: $likesStrawberry)[I like strawberry ice cream.](else:)[I do not like strawberry ice cream.]
    

    note: I have added extra indentation and line-breaks to the above examples to make them more readable, these indentation and line-breaks can be removed.
  • Great thanks! If, however, the story goes in a non-linear path and there are are questions that have not had to be answered, is there a way of adding something that says if neither true nor false, print nothing?
  • So instead of a binary value (Yes and No / true or false) you need a ternary value (Yes, No, Unanswered), there are a number of ways to implement these.

    At the start of your story assign a default value of "unanswered" to all of your question variables, Harlowe has a special startup tag which can be assigned to a passage to do this.
    (set: $likesIcecream to "unanswered")
    (set: $likesStrawberry to "unanswered")
    ... etc ...
    
    Then change the question passages to assign "yes" and "no" instead of true and false:
    Do you like Ice Cream?
    (link: "Yes")[
    	(set: $likesIcecream to "yes")
    	(goto: "Question 2")
    ]
    (link: "No")[
    	(set: $likesIcecream to "no")
    	(goto: "Question 2")
    ]
    
    Then change the final passage to take the three possible values into account:
    (if: $likesIcecream is "yes")[I like ice cream.]
    (else-if: $likesIcecream is "no")[I do not like ice cream.]
    (else:)[Whatever you want to display if the Reader did not answer the related question]
    
    (if: $likesStrawberry is "yes")[I like strawberry ice cream.]
    (else-if: $likesStrawberry is "no")[I do not like strawberry ice]
    (else:)[Whatever you want to display if the Reader did not answer the related question]
    
  • Perfect, thanks so much for your help!
Sign In or Register to comment.