Either to randomize a question by using prompt

0 votes
asked Mar 3 by stefvanoevelen (200 points)

I'm trying to make a random question by using the either, so if one or the other one has been choose, it will ask a different question, but i can't figure it out...

(set: $either to (either: 1, 2))

$either is this.

(set: $test to (prompt:"yes or no","no" (if: $either is 1)))
(set: $test to (prompt:"black or white","white" (else-if: $either is 2)))

is it even possible or did u just write the code in wrong order?!

1 Answer

0 votes
answered Mar 3 by greyelf (97,410 points)
selected Mar 3 by stefvanoevelen
 
Best answer

Your example only has two possible outcomes (either returns 1 or 2) which means you should be using a structure that combines an (if:) macro with an (else:) macro. It also only uses the value of (either:) macro for a single purpose (as the condition) so where is no real need for the $either variable.

Try something like the following.

(if: (either: 1, 2) is 1)[
	(set: $test to (prompt:"yes or no","no"))
]
(else:)[
	(set: $test to (prompt:"black or white","white"))
]


note: Personally I would use the (random:) macro instead of (either:) because both of these macros works by generating a random number. The (random:) macro simply returns that random number, where as the (either:) macro uses that random number to determine which of the supplied items to return. In your particular use case (returning 1 or 2) the (either:) macro has to work a little harder to basically achieve the same result.

The following uses the (random:) macro, it looks very similar to the above (either:) TwineScript example.

(if: (random: 1, 2) is 1)[
	(set: $test to (prompt:"yes or no","no"))
]
(else:)[
	(set: $test to (prompt:"black or white","white"))
]

 

commented Mar 3 by stefvanoevelen (200 points)
Thanks man!

You helped me quite allot!
You know allot of this twine thing!
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...