Hiding Codex

If you are requesting technical assistance with Twine, please specify:
Twine Version: Twine 2.3.13
Story Format: Sugarcube 2.34.1

Hello. I am new to Twine and JavaScript, having mostly used renpy before.

I would like to create a character codex with information on the characters and lore as the protagonist meets them. Would there be a way to do that while also making sure the $variable doesn’t show in the code?

Along with that, I would also like to hide the codex until the protagonist reaches a certain point in the story. Is there a way to do that too?

I’m not sure what you mean by “the $variable doesn’t show in the code”.

About your other question you may write every relevant information on a dedicated passage.

Passage “John Doe”

John Doe is a half caucasian half asian thirty something man. His hands are callous, he's probably a farmer or a manual worker...

As long as you do not call for the passage “John Doe”, your reader won’t know the information.
If you need to call for the “John Doe” passage, there’s more than one way, most notably

<<include "John Doe">>


[[John Doe]]

With the latter case you may want to include a <<back>> in your “John Doe” passage.

Another possible solution:

Create a passage called “StoryMenu” (this is a special passage used to add elements to the UI bar - see SugarCube v2 Documentation). Put the following code in that passage:

<<if hasVisited("ShowCodex")>>

This assumes you have a passage named “ShowCodex” somewhere in the story (of course, you can name it something else), and after the player has visited that passage once, a button will be displayed in the sidebar for the rest of the playthrough, leading to the “Codex” passage.

In the “Codex” passage you can have code like this:

<<if $johnmet>>Description of John<</if>>

<<if $janemet>>Description of Jane<</if>>

[[Close Codex|previous()]]

(just put <<set $johnmet to true>> in the passage where the player meets John, etc.)

The previous() function makes sure you’ll always go back to the last visited passage when you close Codex. Just make sure to delete the passage named “previous()” Twine will create automatically.

(Edit: alternatively, if you always meet each NPC in one set passage, you can skip setting the $johnmet, etc. variables and change the code in the “Codex” passage to the following:

<<if hasVisited("MeetJohn")>>Description of John<</if>>

<<if hasVisited("MeetJane")>>Description of Jane<</if>>

This of course assumes you meet John in the passage titled “MeetJohn” etc.)

Step 1 Create a passage with any title, and with the tag widget, then enter this

<<widget "codex-entry">><<if hasVisited($args[2])>><<link $args[0]>><<replace "#codextarget">><div><<print $args[1]>></div><</replace>><</link>><<endif>><</widget>>

Step 2 Next, create a passage specifically for the codex called codex. Simply link to it like any other passage.

Repeat the widget as much as you like as shown below. Argument 0 is the character name, argument 1 is the character description, and argument 2 is the passage in the story where you meet the character.

<<codex-entry "Alice" "Alice is a person" "alicemeet">> 
<<codex-entry "Bob" "Bob is a person too" "bobmeet">>
<<codex-entry "character" "description" "passage">>
<<codex-entry "..." "..." "...">>
<<codex-entry "..." "..." "...">>

<div id="codextarget"> </div>

[[Close codex|$prevpassage]]

Step 3. To make it accessible, create a passage called StoryMenu and insert this.

<<if hasVisited("X")>>[[codex]]<<endif>>

Where X is the passage at which you want the codex to start appearing…probably alicemeet in the above example.

Step 4. To make the close link work, we need to mark every passage except for ‘codex’ as a possible previous passage. Create a passage called PassageFooter and enter this:

<<if passage() neq "codex">><<set $prevpassage to passage()>><<endif>>

Thank you everybody for your answers! It really helped a lot.