0 votes
asked ago by (2.2k points)
edited ago by

Using Harlowe 2

So my code looks something like:

(set: $a1 to (either: "option 1", "option 2", "option 3"))
(set: $a2 to (if: $a1 is "option 1" (either: "option 1.1", "option 2.2", "option 3.3"))(if: $a1 is "option 2" (either: "option 4.4", "option 5.5", "option 1.1"))(if: $a1 is "option 3" (either: "option 6.6", "option 2.2", "option 4.4")))

I am trying to make the second variable recognize a string variable and choose a random string from the list to set it as. Am I making sense? I've tried looking at the dm macro, datamapping I think it's called, but I don't entirely understand what I'm reading so I don't know how to use it and apply it to the situation I'm facing.

Thank you in advance!

1 Answer

+1 vote
answered ago by (109k points)
selected ago by
 
Best answer

The simplest method you can use to assign your $a2 story variable a random value based on the current value of your $a1 story variable is to is use an (if:) macro and (else-if:) macro structure like the following...

(set: $a1 to (either: "option 1", "option 2", "option 3"))
(if: $a1 is "option 1")[
	(set: $a2 to (either: "option 1.1", "option 2.2", "option 3.3"))
]
(else-if: $a1 is "option 2")[
	(set: $a2 to (either: "option 4.4", "option 5.5", "option 1.1"))
]
(else-if: $a1 is "option 3")[
	(set: $a2 to (either: "option 6.6", "option 2.2", "option 4.4"))
]
A1: $a1
A2: $a2


However if you really want to use a more resource & memory intensive meta-data driven method that involves a Data-map (the (dm:) macro) and some Arrays (the (a:) macro) you could do something like the following..

(set: $a1 to (either: "option 1", "option 2", "option 3"))
(set: _options to (dm:
	"option 1", (a: "option 1.1", "option 2.2", "option 3.3"),
	"option 2", (a: "option 4.4", "option 5.5", "option 1.1"),
	"option 3", (a: "option 6.6", "option 2.2", "option 4.4")
))
(set: $a2 to (either: ...(_options's ($a1))))
}

 

commented ago by (2.2k points)
I ended up using the data-map and array combo and it works perfectly! I never realized how useful both features could be, mostly because I didn't understand how to use them. This has been so helpful, thank you very much.
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.
...