15.10. Adding and removing rows

| Chapter 15: Tables |

| 15.10. Adding and removing rows

Writing in new rows is simple, once we can find space for them:

choose a/the/-- blank row in/from (table name)

This phrase chooses a row in the given table which is currently blank under every column. A run-time problem message is issued if no rows are blank. Example: choose a blank row in Table 3; now element entry is "Fluorine"; now symbol entry is "F"; now atomic number entry is 9; now atomic weight entry is 19;

To avoid problem messages, it can be important to worry about free space. To that end we can not only find the number of rows (as we have already seen) but also the number currently blank and not blank:

number of blank rows in/from (table name) ... number

This phrase produces the number of rows in the given table which are entirely blank (that is, blank under every column).

number of filled rows in/from (table name) ... number

This phrase produces the number of rows in the given table which are not entirely blank (that is, at least one column has a value in this row).

"Filled" here really means "non-blank": a row can be filled in this sense even if only one of its values exists. Since every row is either blank or filled, it must be true that:

> the number of blank rows in Table 3
> the number of filled rows in Table 3

add up to "the number of rows in Table 3".

We've seen that blank entries can be filled with values using "now":

> now symbol entry is "F";

But the same method can't be used to put blanks back, since a blank is not a value. Instead:

blank out (a table entry)

This phrase replaces the entry referred to with a blank, erasing any value previously stored there. Example: choose row 1 in the Table of Fish Habitats; blank out the salinity entry;

These more destructive phrases need a steady hand:

blank out the whole row

This phrase replaces the currently chosen row with blanks, erasing any value previously stored under any of the columns. Example: choose row 1 in the Table of Fish Habitats; blank out the whole row;

blank out the whole (table column) column in (table)

This phrase replaces the currently chosen column with blanks, erasing any value previously stored in any of the rows. Example: blank out the whole salinity column in the Table of Fish Habitats;

blank out the whole of (table)

This phrase replaces every row of the currently chosen table with blanks, erasing any value previously stored anywhere in it. Example: blank out the whole of the Table of Fish Habitats; This is only really useful when a Table is being used to hold working space for some calculation or other.

| Previous builds allowed the following: delete (a table entry)
This phrase is now deprecated, and is exactly equivalent to the preferred form, blank out (table entry)

263
| Example Odyssey A person who follows a path predetermined and stored in a table, and who can be delayed if the player tries to interact with her. |
RB

"Odyssey" Corinth is a room. Athens is east of Corinth. Epidaurus is southeast of Corinth and east of Mycenae. Mycenae is south of Corinth. Olympia is west of Mycenae. Argos is south of Mycenae. Thebes is northwest of Athens. Pylos is south of Olympia. Sparta is east of Pylos and south of Argos. Delphi is northwest of Thebes. Athena is a woman in Athens. Athena will proceed, unless delayed, through a list of locations stored in a simple table. Rather than using Inform's route-finding abilities ("the best route from..."), we simply move Athena from one location to the next, not even using the going action: she moves in mysterious ways, as befits a goddess. Table of Athena's Movement destination Thebes Delphi Thebes Athens Corinth Mycenae Every turn when Athena is active: repeat through the Table of Athena's Movement: let last space be the location of Athena; if Athena can be seen by the player, say "Athena heads to [the destination entry]."; move Athena to destination entry; if Athena can be seen by the player, say "Athena arrives from [the last space]."; blank out the whole row; rule succeeds. By blanking out the table line by line, we make sure that we never lose our place in the path. Since we want the player to be able to talk to Athena, we need a way to stall her in her path, as well. Athena can be active or passive. Athena is active. Before doing something to Athena: now Athena is passive; say "Athena waits around patiently, though you can tell she would like to leave..." Instead of telling Athena about something: say "She watches you patiently as though to say that she already knows." Instead of asking Athena about something: say "Her response is inscrutably ancient and Greek. Afterwards you remember only the flash of bright eyes." Finally, we do need to wake Athena up again if she has become passive. The following rule will occur after the movement rule just because of code ordering, though we could make matters more explicit if we needed to: Every turn when Athena is passive: now Athena is active. Test me with "east / northwest / wait / examine athena / wait".

Previous | Contents | Next