0 votes
by (300 points)

I'm trying to make a link that sends the player to the next passage but if the player doesn't have the "key" the link "Open the door" should change to "You need a key"

Passage#1
(set: $key to "false")
Passage#2
I can't find the video that shows how to change the $key to "true" (like its an item) 
Passage#3 where lets say the player has the key my code is

(link: "Open the door")[
    (if: $key is "false")[
         (replace: ?Open the door)[You need a key]
         ](else:)[
        ]
        (goto: "Next passage")
]
]

but when I click "Open the door" even though I set $key to "false" on the previous passage it still sends me to the next passage.

 

2 Answers

+1 vote
by (23.6k points)

As far as I can tell you misplaced your brackets:

(link: "Open the door")[
    (if: $key is "false")[
         (replace: ?Open the door)[You need a key]
         ](else:)[
        (goto: "Next passage")]
]

 

by (300 points)
Thank you now it works as I want it to but the only thing that bugs me is that when i click the "Open the door" link when I don't have the $key I get the message "You need the key" but it comes with an "Unexpected identifier"bug
by (23.6k points)

Try putting quotes around "Open the door":

(replace: ?"Open the door")[You need a key]
by (300 points)
Nope I still get the same bug...
by (23.6k points)

Sorry - usually don't work with Harlowe. This works for me:

|test>[
	(link: "Open the door")[
	    (if: $key is "false")[
	         (replace: ?test)[You need a key]
	         ](else:)[
	        (goto: "Next passage")]
]
]

 

by (300 points)
Works perfectly thank you very much!
+1 vote
by (159k points)
(set: $key to "false")

If a variables is being using representing a boolean True / False (or Yes / No, On / Off, etc) state then you should be using the Boolean true and false literals instead of a String "true" of "false" value.

(set: $key to true)

(set: $key to false)

This then allows you to write more concise expressions within your (if:) macros, like so.

(set: $key to true)

(if: $key)[This text will only appear if the key variable equals true!]

(set: $key to false)

(if: not $key)[This text will only appear if the key variable equals false!]

 

...