Howdy, Stranger!

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

Multiple Choice Survey: Keeping Track of Responses

New to Twine but liking it lots so far. I've only done very simple operations so far so apologies for the noobness.

I want to create a "What kind of [whatever] are you?" type survey in Twine2 of about 10 questions, with A, B, and C as multiple choice options. At the end of the survey, I want to display a message reading "You answered 'B' [or whatever] most often. That means you are most likely a [whatever]."

So it seems my tasks are:
1. To create a tally of which options are chosen
2. To determine which response was the most common one given
3. To display the "That means you are a [whatever]" message based on the result of #2
4. To then erase results and start over for the next quiz-taker

I can only get as far as setting up the questions, options, and moving to the next question after a response. I don't know anything about how to approach the steps above. What do I need to learn?

Comments

  • edited October 2015
    Firstly you need to state which story format you are using, as answers can be different for each one. I am going to assume that you are using Harlowe.

    You can use $variables to track information in your stroy, like what choices are selected.

    The following example is made up of four passages named Startup, Question 1, Question 2, and Results.

    1. Startup
    This passage is where you initialize the main variables of your story, create a new passage and name it Startup, assign it a startup tag, and add the following to it:
    (set: $answers to (array:))
    (set: $countA to 0)
    (set: $countB to 0)
    (set: $countC to 0)
    
    note: You could name the above passage anything you wished, the important part was the startup tag which lets Harlowe know that this passage need to be executed before the main passage of the story is displayed.

    2. Question 1
    This passage is the starting point of of your story, Add the following code to it:
    Q1. Some question?
    
    (link: "A. A possible answer")[
    	(set: $countA to it + 1)
    	(set: $answers to it + (array: "A"))
    	(goto: "Question 2")
    ]
    (link: "B. A possible answer")[
    	(set: $countB to it + 1)
    	(set: $answers to it + (array: "B"))
    	(goto: "Question 2")
    ]
    (link: "C. A possible answer")[
    	(set: $countC to it + 1)
    	(set: $answers to it + (array: "C"))
    	(goto: "Question 2")
    ]
    
    The above uses a variable ($answers) to track each option that is selected, and three variables ($countA, $countB, $countC) to track how many times each option was selected.
    note: I have added extra line-breaks to the above code to make more readable, these line-breaks can be removed.

    3. Question 2
    You will need to create this (and all the other question passages) yourself because Twine 2 does not recognize Harlowe's (goto:) macro so it will not create the passage for you.
    It is similar to Question 1 but it leads to the Results passage instead.
    Q2. Some question?
    
    (link: "A. A possible answer")[
    	(set: $countA to it + 1)
    	(set: $answers to it + (array: "A"))
    	(goto: "Results")
    ]
    (link: "B. A possible answer")[
    	(set: $countB to it + 1)
    	(set: $answers to it + (array: "B"))
    	(goto: "Results")
    ]
    (link: "C. A possible answer")[
    	(set: $countC to it + 1)
    	(set: $answers to it + (array: "C"))
    	(goto: "Results")
    ]
    

    4. Results
    Again you will need to create this passage yourself. It first determines what the maximum count ($maxCount) was and then determines which option counts ($countA,$countB,$countC) are equal to that maximum.
    Your answers were (print: $answers)
    
    {(set: $maxCount to $countA)
    (if: $countB > $maxCount)[
    	(set: $maxCount to $countB)
    ]
    (if: $countC > $maxCount)[
    	(set: $maxCount to $countC)
    ]
    (set: $maxOption to (array:))
    (if: $countA is $maxCount)[
    	(set: $maxOption to it + (array: "A"))
    ]
    (if: $countB is $maxCount)[
    	(set: $maxOption to it + (array: "B"))
    ]
    (if: $countC is $maxCount)[
    	(set: $maxOption to it + (array: "C"))
    ]}
    The option(s) you selected the most was (print: $maxOption), selected (print: $maxCount) times.
    

    The above should be enough to get you started.
  • Wow, that's great! Thanks for the response. I'll give it a try.
    And yes, I'm using Harlowe—sorry I didn't mention it.
Sign In or Register to comment.