Notebooks

ADRIFT 5 Help ›› Creating Games ›› Tutorials ›› Intermediate ››
Parent Previous Next

Notebooks

A notebook is an object that the character can carry around with them, but also write notes in.  Implementing this is actually very straightforward.

Creating the Notebook

The first thing we need to do is actually create a notebook object.  This is just a dynamic object with a readable property.  So firstly, create a new object and give it a suitable name such as "notebook".  You might also want to give it an alias of "book".



I have set the start location for the book to just be held by the player character.


On the Properties tab, select the Object is readable property.  Because we want the notebook to have a different description when read to just examining it, also select the ... and description when read property.  This can be left blank.  We will modify this property later.



Click OK to add the object.

Writing in the book

To write in the book, we need to create a new verb that ADRIFT understands, since "write" is not a command in the standard library.  So create a new General task and give it the command "write %text%".  


%text% is a reference.  This will match anything the player types, much like a wildcard, but also stores the matched text in the %text% reference which you can use in text and expressions.


So we can echo back to the player what they just typed, like so:



On the Restrictions tab, add a restriction that we must be able to see the notebook, like so:



And then on the Actions tab, add an action that sets the ... and description when read property to the following expression:



If this expression seems a bit confusing, what this is doing is setting the description when you read the book to three things concatenated together.  



So this action will set the read description to the current read description, plus a new line, plus the text the user just typed.  Or in other words, it will simply append the text the user typed onto the property.


Make sure you make the task repeatable by ticking the Task is Repeatable checkbox, then click OK to add the task.


If you now play the game, you should find that you can type "write <whatever>" to write in the notebook, and if you type "read notebook" you should see all the things you have written in the book.

Enhancing the notebook

The above should work fine, but it is a little rough around the edges.  Firstly, it would be nice to know that you have written in the book when you just examine it.  So we can create an alternative description to give us this extra information.  


Edit the notebook object, and add a new alternative description, setting it to append to previous text.  Add a restriction that the read description for the notebook must not be expression "" (i.e. blank), like so:



And then add text to say that the book has been written in.  Give the alternative description tab a suitable name:


Enhancing reading the notebook

With the above implementation, when you read the notebook it will simply echo back everything you have written into it.  It would be nicer to have some sort of description around what you've written.


Currently, the "read <object>" library task will just return %object%.ReadText, i.e. the ... and description when read property of the referenced object.


We can change this by overriding the Read objects task for the notebook.  So right-click on the notebook object in the objects list and select Add Specific Task > read a notebook (or you can just add a new task, set it to Specific and select the notebook for the object).  This will bring up the task editor, set to override the Read objects task for the notebook.


Type the name of the notebook key (you can drag the notebook onto the text box to get it's key), then type a dot, then type ReadText.  This will now return the read description of the notebook, in the same way as the default task.  You can now enter some surrounding text to improve the readability of the book, like so:



Notice that we have used HTML markup to italicise the text we have written.


We can also add an additional restriction for this task, so that if we try to read it before anything has been written in the notebook, we give a sensible reply.  We can use the same restriction as we added to the notebook object itself, but this time we give an error message:



You might also want to create a pen object, and add a restriction to the write task that you must be holding the pen.


As a further exercise, you might want to create a task that accepts "write %text% in %object%", so that the player can be more explicit.  If you do this, you can redirect the "write %text%" command to the new task by executing the other task, passing %text% and Object1 as parameters.