Twine 2.5.1
Harlowe 3.3.3
Hello, first of all I’m new to all of this, but trying my best, forgive me if my code is ugly.
I’m trying to get a set outcome (or outcomes) from an input box. Once the box is filled, the outcome will print below the input box. At first I was using else-if statements, but it was getting very long, and some keywords (labeled as items in my example code) are present for multiple Xs, and the else-ifs would stop at the first met condition, when I want all outcomes that meet the conditions to show. So I attempted using a datamap, trying to tie all the Xs and their outcomes into one variable, and having it all checked at once. It does not work.
The error I get says
Only strings and numbers can be used as data names for an empty datamap, not an array (with the string “item1”, the string “item2”, ).
This is on my startup passage
(set: $X1 to (a: "item1", "item2", "item3")
(set: $X2 to (a: "item3", "item4", "item5")
(set: $checkX to (dm: $X1, "outcome 1", $X2, "outcome 2"))
and then on the actual input screen is
(input-box: bind $userfill)
(live: 1s)[
(if: $userfill is "")[]
(else-if: $userfill contains some of $checkX)[(print: $checkX's 2nd)]
(else:)[only shows when not blank and no items]
]
here I’m trying to get the listed outcome from whatever X the conditions met.
So, if the input box has item1 or item2, the outcome will be “outcome 1”. If it has item4 or item5, it’ll be “outcome 2”. If it’s item3, the outcome would be both “outcome 1” and “outcome 2”
it did work initially when I had
(else-if: $userfill contains some of $X1)[outcome 1]
(else-if: $userfill contains some of $X2)[outcome 2]
but it was getting very very long (there’s 28 outcomes, and I can’t lessen the amount), and like I said previously, it would stop at the first met condition when I wanted it to show every outcome the conditions matched. Would I just need to use if statements rather than else-ifs to get that to work? I’d prefer a neater solution, but anything that works is better than what doesn’t. Is there a better way to go about what I’m doing?