How to create a codex
What is a Codex?
In my story, the codex is a page with a list of entrees of different creatures. Each creature has it's own page dedicated to it, and the page always links back to the codex. The key thing about the codex, is that it's accessed through an item and as such can be used at any time in the story.
So in abstract form, it looks like this:
Any Page <------> Codex <------> Any Creature Entry
You can't view any creature entry without first going to the codex, and you can only go back to the story through the codex.
How do you do it?
Well, it wasn't too hard, all you need is two variables, some scripts, and an item to act as the codex. In order to access the codex at any time, the player just uses the item that represents the codex. Set it so when the item is used, the player is always moved to the same page (in my case I moved them to page 10).
The two variables I used were:
ISCODEX - Used to determine if the current page is within the codex (Is either 0 or 1)
LASTPAGE - Used to determine the page you came from when you entered the codex (Is any number)
The Scripts were:
Global Page Script
|IF %ISCODEX = 0 AND $PAGEID != 10 THEN
%LASTPAGE := $PAGEID
What this is saying is that, so long as the current page isn't within the codex, and is not the codex page (my codex was on page 10) then LASTPAGE is equal to the current page.
Codex Page Script
|%ISCODEX := 1|
Pretty straight forward. This means that once you have entered the codex front page, any link you go to is within the codex and will not be saved as %LASTPAGE.
Codex Page - Return to Story Link
|$DEST := "@P" + %LASTPAGE
%ISCODEX := 0
This is the scripting in the link on the codex page, which will take you back to where you where in the story. The first line is setting the destination of the link to whatever the %LASTPAGE variable is, the "@P" is just syntax that the site uses for page numbers. The next line sets the ISCODEX variable back to zero, since you're leaving the Codex and going back to the story.
You can set the "Return to Story" link on the "Codex" page to anything, I just set it to link back to the Codex page. It doesn't matter what you set it to since the destination will be changed by the script.
It works with multiple chapters. I have my codex and all it's entrees in it's own seperate chapter to organize things. Since it links directly to the page number, there are no issues with moving between chapters. By this I mean the Codex page can be accessed by, and move back to, pages within different chapters.
We need the additional ($PAGEID != 10) check in the global page script because when you enter the Codex page, the global script would run before the page script. This means that it's checking the Codex variable before we change it. We could make the change in the global variable, but since we only need to change it on the one page, there is no point in executing it on
You can set certain links within the to only be visable when the player has a certain item, or a variable is a certain number. This can allow you to slowly show the player links throughout the game and makes it seem like they are slowly discovering and recording events or creatures they have found in the codex.
Obviously you can use this for more than just creatures. It can be used as an advanced journal or history book to explain past events, or it can hold information on different characters, or other things that I can't think of and you can.