§23.14. Writing, reading and appending text to files
Text can also be saved to a file, and again all file-handling is automatic:
write (text) to (external file)
This phrase makes the given text become the entire contents of the named file. Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
write "Jackdaws love my big sphinx of quartz." to the file of Abecedary Wisdom;
append (text) to (external file)
This phrase adds the given text to the end of the current contents of the named file (creating it if it does not exist on disc). Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
append "Jinxed wizards pluck ivy from the big quilt." to the file of Abecedary Wisdom;
The quoted text can, of course, contain substitutions, so can be long and complex if need be.
Text from a file is printed back with the text substitution:
say "[text of (external file)]"
This text expands to the contents of the named file. Note that files must have been declared, and must be referred to by their Inform names, not by textual filenames. Example:
"[text of the File of Abecedary Wisdom]"
To copy one file to another, for instance,
write "[text of the file of Abecedary Wisdom]" to the file of Secondary Wisdom;
![]() | Start of Chapter 23: Figures, Sounds and Files |
![]() | Back to §23.13. Writing and reading tables to external files |
![]() | Onward to §23.15. Exchanging files with other programs |
|
The implementation here is much like that of the previous example, except that we allow the player to write his notebook input as a separate command, leading to an exchange such as
The opening is much as before:
Now what happens is that the player, having typed WRITE IN NOTEBOOK, will be faced with a ">>" prompt instead of the usual ">": a sign that the input mode has changed. The next code is to react to reading a command. Whatever the player types at the >> prompt when the target jotter is set will now be recorded in the notebook, though with a character limit of about 60-100 characters depending on how much upper-case and punctuation he uses. (There are ways to lift the character length restriction as well, but they would take us into deeper waters.)
|
|
The implementation here is much like that of the previous example, except that we allow the player to write his notebook input as a separate command, leading to an exchange such as
The opening is much as before:
Now what happens is that the player, having typed WRITE IN NOTEBOOK, will be faced with a ">>" prompt instead of the usual ">": a sign that the input mode has changed. The next code is to react to reading a command. Whatever the player types at the >> prompt when the target jotter is set will now be recorded in the notebook, though with a character limit of about 60-100 characters depending on how much upper-case and punctuation he uses. (There are ways to lift the character length restriction as well, but they would take us into deeper waters.)
The implementation here is much like that of the previous example, except that we allow the player to write his notebook input as a separate command, leading to an exchange such as
The opening is much as before:
Now what happens is that the player, having typed WRITE IN NOTEBOOK, will be faced with a ">>" prompt instead of the usual ">": a sign that the input mode has changed. The next code is to react to reading a command. Whatever the player types at the >> prompt when the target jotter is set will now be recorded in the notebook, though with a character limit of about 60-100 characters depending on how much upper-case and punctuation he uses. (There are ways to lift the character length restriction as well, but they would take us into deeper waters.)
|