0 votes
by (410 points)
edited by
I'm trying to make it where if the player has seen a knife in one of the rooms, then when they go to the attic it will add additional text saying "You see another knife from the left room."

2 Answers

0 votes
by (159k points)
selected by
 
Best answer

The following attempts to clarify the answer given by @Seyru.

You can use a story variable to track is the player has seen a knife in another room.

1. Initialise your story variable within your project's startup tagged special passage.

If you don't have such a passage yet then add a new Passage to your project, you can assign it any name you like because the name isn't important but I name mine Startup, and then assign this new passage a Passage Tag of startup (all lower-case letters). Place the following code within this passage's body...

(set: $seenKnife to false)


2. Set the story variable to true when the player first sees a knife within the other passages.

(set: $seenKnife to true)


3. Check the current value of the story variable in your attic passage.

You see {(if: $seenKnife)[another](else:)[a]} knife from the left room.

 

by (410 points)
Thank you both for these answers, but I have fixed the problem. I watched a video about this problem and learned about sets and ifs. I now have set it up.
0 votes
by (2.4k points)

Hello there, 

Maybe you could do something like this : 

(set: $seenKnife to true) 

You see {(if: $seenKnife)[another] (else:)[a]} knife from the left room. 

(set: $seenKnife to false) 

You see {(if: $seenKnife)[another] (else:)[a]} knife from the left room. 

Here, when $seenKnife is true (the knife has been seen), it writes "another". If $seenKnife is false (the knife has not been seen), it writes "a" instead. 
 

If there are plenty of knives to be seen, you could also do it like this :

 

(set: $seenKnife to 0) 

You saw {(if: $seenKnife is 0)[no knives yet.] (else-if: $seenKnife is 1)[one knife ! Great.] (else-if: $seenKnife is 2)[two knives. You're a knife finder. That's a gift. Really.](else-if: $seenKnife is 3)[three knives. I'm amazed. There were only two knives in the game.]} 

(set: $seenKnife to 1) 

You saw {(if: $seenKnife is 0)[no knives yet.] (else-if: $seenKnife is 1)[one knife ! Great.] (else-if: $seenKnife is 2)[two knives. You're a knife finder. That's a gift. Really.](else-if: $seenKnife is 3)[three knives. I'm amazed. There were only two knives in the game.]} 

(set: $seenKnife to 2) 

You saw {(if: $seenKnife is 0)[no knives yet.] (else-if: $seenKnife is 1)[one knife ! Great.] (else-if: $seenKnife is 2)[two knives. You're a knife finder. That's a gift. Really.](else-if: $seenKnife is 3)[three knives. I'm amazed. There were only two knives in the game.]} 

(set: $seenKnife to 3) 

You saw {(if: $seenKnife is 0)[no knives yet.] (else-if: $seenKnife is 1)[one knife ! Great.] (else-if: $seenKnife is 2)[two knives. You're a knife finder. That's a gift. Really.](else-if: $seenKnife is 3)[three knives. I'm amazed. There were only two knives in the game.]} 


 

Here, the game checks how many knives you saw, and acts accordingly

by (410 points)
Thank you for this answer, but whenever I try to test play it, the game says:

 

You see (if:)'s 1st value is the number 0, but should be a boolean. another

There's nothing before this to do (else:) with a knife in the attic.

 

Is this normal? Sorry if this is obvious, but I'm new to this program.
by (2.4k points)
I don't have any issue when testing it out on my side.

Did you copy/paste what I wrote ?
by (410 points)
Yes, I did, but whenever I click play when I add it, it says that.
by (2.4k points)
Please send me your code, maybe a typo got its way through.
by (410 points)
Ok, here it is:

You see {(if: $seenKnife)[another] (else:)[a]} knife in the attic.

You see {(if: $seenKnife)[another] (else:)[a]} knife in the attic.

You also see a doll hanging from the roof of the attic, it's eyes sink into your soul as if it were haunted. What do you do?

[[Pick up the knife|Knife]]
by (2.4k points)

Alright, so it probably doesn't work because you didn't set $seenKnife in your example.

(set: $seenKnife to true)

You see {(if: $seenKnife)[another] (else:)[a]} knife in the attic.

You also see a doll hanging from the roof of the attic, it's eyes sink into your soul as if it were haunted. What do you do?

[[Pick up the knife|Knife]]

I modified it, setting $seenKnife to true. (Meaning he saw the knife) 
Try it out. If he didn't see the knife, set $seenKnife to false :)

by (410 points)
Do i have to have it in the same box? That was just the attic box. I activated it in the box where you observe the knife in the left room.
by (2.4k points)
Send me that part as well, maybe the error lies there then. It should be working, even if you set it up elsewhere :(
by (410 points)
Sorry, but for some reason, it needs to check my comment.
by (2.4k points)
I tried to set up $seenKnife in another passage, and it worked well for me. So I don't really understand what's going wrong. Check if the setting up is correct !
by (410 points)
What did you do to set it up? I am still new with variables and stuff, so I probably didn't properly set it up correct
by (2.4k points)
(set: $seenKnife to true)
Should be good.
Then in another passage, $seenKnife will still be set to true. It will be set to true as long as you do not change it within the story.
by (159k points)

The issue is caused because you aren't initialising your story varaibles before you reference then within the conditional expresson you are passing to your (if:) macros, and Harlowe automatically initialises such variables to a default value of zero (0).

eg. Lets assume you have a Passage containing the following two conditional expressions, the first of which is testing to see if $seenKnife is equal to Boolean true...

<!-- You haven't assign $seenKnife a default value yet. -->

(if: $seenKnife)[show an error about zero not being a Boolean]

<!-- Harlowe assigned zero (0) to $seenKnife in previous conditional expression. -->

(if: $seenKnife is 0)[The variable is zero now]

...and if you haven't previously assigned $seenKnife a value then Harlowe will automactically initialise the variable to zero (0) before testing it's value. This is why the second conditional expression will evaulate to true, because $seenKnife now does contain a value of zero.

It is a good idea to always initialise your story variables sometime before you first reference them in either a conditional expression or before you output their current value to the page.
The best place to do such initialisation is within your project's startup tagged special passage like so...

(set: $seenKnife to false)


Now if we visit the previous Passage with the conditional expressions again...
(note: I have added a third to show how to test for Boolean false)

<!-- You have initialised $seenKnife to a default value. -->

(if: $seenKnife)[nothing displayed because value is false]

(if: $seenKnife is 0)[nothing displayed because value is false]

(if: not $seenKnife)[displayed because value is false]

... the will notice that the error message has gone away.

 

by (2.5k points)
You do it the same way you would in science/grammer...

If this happens, then this will happen
...