0 votes
by (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
by (159k points)
selected by
 
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"))
]

 

by (200 points)
Thanks man!

You helped me quite allot!
You know allot of this twine thing!
...