0 votes
by (250 points)

Hey gang. New Twine user here. Just trying to set up a quick puzzle to get a handle on some of the techniques/concepts. Right now what I'm trying to do is allow the player to approach an office desk and punch holes into a card (if they already have "cards" in their inventory) which then adds a "hole punched card" to their inventory. If they do not have the item in the their inventory, the passage will read "Hm, there's a hole puncher here. I wonder what it's for." As of now, that part works fine with the following code:

(if: $inv contains "cards")[Oh! You can [[hole punch one of those cards|Hole punched card]] you picked up]
(else:)[Hm. There's a hole puncher here. I wonder what I can use it for...]

However, I want to add a third option where the player has returned to the office desk with "hole punched card" in their inventory. I want the game to tell them "You've already used this," effectively cutting the player out of a loop where they can punch holes into cards forever. So I tried this:

(if: $inv contains "cards")[Oh! You can [[hole punch one of those cards|Hole punched card]] you picked up]
(elseif: $inv contains "hole punched card") [You already used this.]
(else:)[Hm. There's a hole puncher here. I wonder what I can use it for...]

And that did not work. So I then tried this:

Your secretary sits at her desk {
(if: $inv contains "cards")[
    Oh! You can [[hole punch one of those cards|Hole punched card]] you picked up
](else-if: $inv contains "hole punched card")[
    You already used this.
](else:​)[
    Hm. There's a hole puncher here. I wonder what I can use it for...
]}.

And that also did not work.

Any suggestions?

1 Answer

+1 vote
by (44.7k points)
 
Best answer
I don't know Harlowe as well as I know the SugarCube format, but the problem appears to be that you're checking things in the wrong order.  You should check to see if they have a hole punched card first, then if they don't have that, check to see if they have a card, then if they don't have that, just comment about the hole puncher.

The problem is that you're doing the "do you have a card" check first, and if that's true, then your code (as it is now) assumes that they need to have the card punched.  That's why it's not working.

Basically, you need to make the first thing you check be the last possibility you can get, then the second thing you check should be the second to last possibility you can get, and so on, until you get down to the last "else" and that should be the initial/default situation.

If it helps, think of it as listing responses by priority.  You put the highest priority responses first and the lowest priority ones last.  So if you're getting the wrong response, then you know you have the priorities in the wrong order, and you need to move the correct response to a higher priority (earlier in the series of if..else checks) than the wrong response you're getting instead.

Hope that helps!  :-)
by (250 points)
Wow, that works! And so simple too! Thanks so much.
...