0 votes
asked 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
answered by (131k 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.

 

commented 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
answered 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

commented 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 !
commented 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
commented 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.
commented by (131k 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.

 

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

If this happens, then this will happen
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...