Referring to objects listed in tables

Is is possible to refer to things listed in tables as objects? For example, something like this (the last line of code, in particular):

[code]Lobby is a room. Bob and Mary are people in the Lobby.

Parking Lot is a room. The Parking Lot is east of the Lobby.

A bicycle is a thing. A VW Bug is a thing. A parakeet is an animal. A St Bernard is an animal.

Table 1
Person Vehicle Pet
Bob bicycle parakeet
Mary VW Bug St Bernard

Every turn:
Repeat with P running through people in the lobby:
If P is a person listed in table 1:
Now the vehicle is in the parking lot.[/code]

That should work if you change the last line to “now the vehicle entry is in the parking lot.”

In addition to what Juhana said, one way to do this is by using the “corresponding entry” syntax from Writing with Inform 16.3:

Every turn: Repeat with P running through people in the lobby: If P is a person listed in table 1: Now the vehicle corresponding to a person of P in Table 1 is in the parking lot.

This will be a bit computationally inefficient, since Inform has to repeat through the table once to check “if P is listed in table 1” and again to find the vehicle corresponding to a person of P in Table 1. (Juhana’s solution avoids this.) If that’s a problem, which it probably shouldn’t be unless your table is huge or you’re running this rule a lot, there’s this less elegant code using the repeating through tables syntax from WI 16.6:

Every turn: Repeat with P running through people in the lobby: repeat through table 1: if the person entry is P: now the vehicle entry is in the parking lot.

Although this might be less efficient in some cases, since it repeats through the entire table even if it’s already found an entry. (It might be possible to use “next” or “break” to cut this off, from WI 11.12, but I haven’t figured out how to do this to cut off the repeat through the table loop but not the repeat through people in the lobby loop.) Note that, if there is more than one entry for Bob in the table, the first code would only put Bob’s first vehicle in the parking lot, while this one puts all Bob’s vehicles in the parking lot (since it does repeat through the whole table).

Another way to do this would be to refactor the loop so you just repeat through the table and then check whether the person in the table is in the lobby:

Every turn: repeat through table 1: if the person entry is in the lobby: now the vehicle entry is in the parking lot.

This is probably even more efficient, since it only repeats through the table once. (Also I think there may be some funny business where sometimes invoking a phrase like “people in the lobby” loops through and checks every person in the whole game, though I don’t know exactly what invokes this.) Like the second one, this will move all Bob’s vehicles into the parking lot.

Hope this helps! (The other way of doing stuff in tables involves choosing row, which is explained in WI 16.5, and which requires you to use the “vehicle entry” syntax; but I couldn’t figure out a sensible way to use that to do what you want. In Juhana’s solution I think that the “if P is a person listed in Table 1” check chooses the first row with P in the person column, so you can then look up the vehicle entry without explicitly saying what row it’s in.)

That’s perfect, thanks!