0 votes
by (120 points)
For reference, this is for a board game with an electronic component. Each player votes for one of three options. The option with the most votes is built on the game board in the first position, the second most in the second position, and the third most in the third position.

I can easily tally the votes using variables. Comparing the results of the vote, since multiple or all results can be a tie is absolute madness. I would like to compare the variables and arrange them from highest to lowest, randomly assigning a spot for any tied results.

Thanks in advance.

2 Answers

0 votes
by (6.2k points)

This checks what a player wants to vote on. 

What do you want to vote for:
(link: 'Triangle')[(set: $triangle to it + 1)]
(link: 'Apple')[(set: $apple to it + 1)]
(link: 'Batman')[(set: $BATMAN to it + 1)]
(link: 'Old Twine Forum :(')[(set: $otf to it + 1)]

Then do this:

(if: $triangle > $apple)[(if: $triangle > $BATMAN)[(if: $triangle > $otf)[(set: $top to 'triangle')](else:)[(set: $second to 'triangle')]](else:)[(set: $third to 'triangle')]](else:)[(set: $last to 'triangle')

This only checks triangle's place. Copy and paste this for all of the others.

Then you can display whatever you want or do whatever with this.

0 votes
by (63.1k points)
edited by

If you were using Harlowe 2.0.1, you could use the (for:) macro to do this easily (you'll need some modification to find the complete order).  Failing that, you could either attempt to use JavaScript, which might be a challenge because Harlowe's APIs are all but inaccessible from within Twine, or attempt to create your own looping mechanism using a combination of (display:) and (replace:) macros, but this is risky and not very intuitive.  Deadshot's code will work, too, but might be a bit unwieldy.

My suggestion is to upgrade to 2.0.1.  It's generally better to be using later versions when it comes to things like this anyway--you should only be sticking with Harlowe 1.2.4 if you really have to.

...