0 votes
by (140 points)
I'm using Harlowe 2.1.0 ot build a story that tracks values via points over the course of the narrative--specifically three: cool, cute, and straightforward.

Tracking the points is no problem using the set function [ex. (set: $cool to $cool + 1)], tracking 3 variables over the course of the narrative.

The tricky part gets to be when I need to serve branches that are conditional between these three (ex. if the most cool points are chosen, then the cool branch gets shown).

I thought that something like (if: $cool is >= $cute, $straightforward) would work, but I get a "1 too many values were given to this (if:) macro" error.

Does anyone have any pointers for making this kind of function work?

2 Answers

+1 vote
by (23.6k points)

You can use the Math.max method to return the element with the highest value out of a group:

(if: Math.max($var1, $var2, $var3, $var4) == $var1)
...
etc.

 

by (140 points)
Okay cool, that seems right in theory!

EDIT: Alas, when I put in (if: Math.max($straightforward_count, $cool_count, $cute_count) == $straightforward_count) I get the error:

"I can't put a new value into the number null.►I tried to perform an operation on some data, but the data's type was incorrect."

:(
by (23.6k points)

Sorry my bad. Not used to working with Harlowe. This should be the correct way of writing something like this:

(if: Math.max($str, $int, $cha) is $cha)[(print: "Success")]

 

+1 vote
by (159k points)

The correct syntax for your (if:) macro example is

(if: $cool >= $cute and $cool >= $straightforward)[
	...
]


note: Read the note in the answer to the How to Stop Endless Header Looping to Specific Passage question for an explanation of why you shouldn't use the is operator with the mathimatical <, > , <=, and >= operators.

by (140 points)
You did it you're a star thank you!
by (140 points)

Hit another bug : /

I need all three variants of these to show up on the same page while guaranteeing that only one of them will load per page(ex.)

  • (if: $straightforward >= $cute and $straightforward >= $cool)[Full disclosure, I literally never do stuff like this, but I just feel like we clicked right off the bat.]
    
    (if: $cute >= $cool and $cute >= $straightforward)[I usually don't do stuff like this, but I'm... excited. ]
    
    (if: $cool >= $cute and $cool >= $straightforward)[I'm usually super busy, so I'm glad we could find time to hang today.]
    
    

    In some instances, it's working and only one of them shows up. In others, I'm getting multiples at once... any ideas how to limit it to only one at a time? 

by (560 points)

Someone correct me if I'm wrong, but it seems like you need to tighten up your conditions. Maybe use the (else-if:) macro.

(if: $straightforward >= $cute and $straightforward >= $cool)[Full disclosure, I literally never do stuff like this, but I just feel like we clicked right off the bat.]

(else-if: $cute >= $cool and $cute >= $straightforward)[I usually don't do stuff like this, but I'm... excited. ]

(else-if: $cool >= $cute and $cool >= $straightforward)[I'm usually super busy, so I'm glad we could find time to hang today.]

 

...