I have a question about using lists as variables. I’m much more interested in learning the particular reason why something I tried didn’t work than I am in learning some other way to accomplish my goal, since that’s already done.
Some time ago I made door-kind that simulates various doors with electronic locks openable using various keycards, and as I was recently going through my code I noticed these somewhat forgotten keycard/door toys and thought it would be interesting to add a second kind of electronic door that simulates a biometric locking system. My initial thought about how to implement such was that I’d assign each (simulated) lock a list of names of characters authorized to access the lock, and that the (simulated) unlocking action for these doors would simply consist of determining if the current actor’s name was listed therein.
I started by writing the following:
[code]A biodoor is a kind of door. A biodoor is usually closed and openable. A biodoor is usually locked and lockable. The description of a biodoor is usually “A sturdy door with a computerized biometric locking mechanism. A fingerprint-scanning device is set in the middle of the door.”. Understand “electronic door” or “door” or “computerized door” as a biodoor.
A biometric scanner is a kind of thing. Understand “biometric scanner” or “scanner” or “scanning device” or “scanner pad” or “scan pad” or “pad” or “glass” as a biometric scanner. The description of a biometric scanner is usually “A hand-sized piece of dark glass, inset at an angle on top a small metal box, is firmly attached to the middle of the door. To unlock the door, one touches one’s hand to the glass; the device then scans the user’s fingerprints and (assuming the user is authorized to access the door) automatically unlocks the door.”. A biometric scanner has a list of text called the authorizedusers. The authorizedusers of a biometric scanner is usually {“nobody”}.
One biometric scanner is part of every biodoor.
The testarea is a room.
A man called George is in the testarea. The player is George.
The southernarea is a room.
A biodoor called the Security Door is south of the testarea and north of the southernarea. The authorizedusers of the Security Door’s biometric scanner is {“George”}.[/code]
That was all fine, and compiled with no problem. I then added a series of checks to redirect all the various ways a character could interact with such a door or scanner to the the action of the actor trying to touch a biometric scanner when the door incorporating it is closed and locked. That was all fine as well. However, when I tried to write the actual rule that would unlock and open such a door, I couldn’t find any relevant phrasing that would compile. For example, my first try was:
[code]Procedural rule for an actor touching a biometric scanner:
ignore the report touching things rule.
Carry out an actor touching a biometric scanner that is part of a biodoor (called hbdr):
if the actor is listed in the authorizedusers of the noun:
change hbdr to unlocked;
silently try the actor opening hbdr;
if hbdr is open:
if the actor is the player:
say “You touch your hand to the scanner and hear a metallic ‘click’ as [the hbdr] unlocks and opens.”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, and you hear a metallic ‘click’ as [the hbdr] unlocks and opens.”;
otherwise:
if the actor is the player:
say “You touch your hand to the scanner, but nothing happens. Something must be wrong with either the scanner or [the hbdr].”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, but nothing happens. Something must be wrong with either the scanner or [the hbdr].”;
otherwise:
if the actor is the player:
say “You touch your hand to the scanner, but nothing happens. You are not authorized to access [the hbdr].”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, but nothing happens. Apparently [the actor] is not authorized to access [the hbdr].”;
otherwise:
stop the action.[/code]
Which failed to compile with the message:
I tried other various combinations of the first few lines, variations on a theme such as:
Carry out an actor touching a biometric scanner that is part of a biodoor (called hbdr):
let curbdl be the authorizedusers of the noun;
if the actor is listed in curbdl:
change hbdr to unlocked;
that all resulted in similar failed compiler messages. I also tried changing the code for the biometric scanner object by defining the list as:
A biometric scanner has a list of people called the authorizedusers. The authorizedusers of a biometric scanner is usually {"nobody"}.
resulting in the compiler errors:
which make little sense to me in this context since both “nobody” and “George” are valid terms for referring to people in this particular code.
What I’m wondering is: why exactly didn’t any of these attempts work?
Although the following probably has little to do with my question, for the sake of anyone interested in the outcome of the experiment I eventually did find a very obtuse way to use the list idea. The following code compiles fine and works fine when substituted for the first lines of the Carry Out rule:
Carry out an actor touching a biometric scanner that is part of a biodoor (called hbdr):
let curbdl be the authorizedusers of the noun;
let checkone be the printed name of the actor;
repeat with checktwo running through curbdl:
if checktwo matches the text checkone:
change hbdr to unlocked;
Since it seems pointless to compose and test against a list if one is going to go to the trouble of changing it to indexed text later, I threw the whole thing out and just set up the doors to work in a somewhat similar way to the keycard doors I already had (which also use indexed text). So in the end I went with the following basic code for the biometric doors:
[code]A biodoor is a kind of door. A biodoor is usually closed and openable. A biodoor is usually locked and lockable. The description of a biodoor is usually “A sturdy door with a computerized biometric locking mechanism. A fingerprint-scanning device is set in the middle of the door.”. Understand “electronic door” or “door” or “computerized door” as a biodoor.
A biometric scanner is a kind of thing. Understand “biometric scanner” or “scanner” or “scanning device” or “scanner pad” or “scan pad” or “pad” or “glass” as a biometric scanner. The description of a biometric scanner is usually “A hand-sized piece of dark glass, inset at an angle on top a small metal box, is firmly attached to the middle of the door. To unlock the door, one touches one’s hand to the glass; the device then scans the user’s fingerprints and (assuming the user is authorized to access the door) automatically unlocks the door.”. A biometric scanner has some indexed text called the authorizedusers. The authorizedusers of a biometric scanner is usually “nobody”.
One biometric scanner is part of every biodoor.
Procedural rule for an actor touching a biometric scanner:
ignore the report touching things rule.
Carry out an actor touching a biometric scanner that is part of a biodoor (called hbdr):
let curper be indexed text;
let curper be the printed name of the actor;
if the authorizedusers of the noun matches the text curper, case insensitively:
change hbdr to unlocked;
silently try the actor opening hbdr;
if hbdr is open:
if the actor is the player:
say “You touch your hand to the scanner and hear a metallic ‘click’ as [the hbdr] unlocks and opens.”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, and you hear a metallic ‘click’ as [the hbdr] unlocks and opens.”;
otherwise:
if the actor is the player:
say “You touch your hand to the scanner, but nothing happens. Something must be wrong with either the scanner or [the hbdr].”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, but nothing happens. Something must be wrong with either the scanner or [the hbdr].”;
otherwise:
if the actor is the player:
say “You touch your hand to the scanner, but nothing happens. You are not authorized to access [the hbdr].”;
otherwise if the player can see the actor:
say “[The actor] touches the scanner, but nothing happens. Apparently [the actor] is not authorized to access [the hbdr].”;
otherwise:
stop the action.
The testarea is a room.
The southernarea is a room.
A man called George is in the testarea. The player is George.
A biodoor called the Security Door is south of the testarea and north of the southernarea. The authorizedusers of the Security Door’s biometric scanner is “george”.[/code]
Which works just fine.
In any case, I’m hoping anyone familiar with list functions can comment on why my attempted usage of a list failed in the original cases, and if there is a way to use a list to achieve the sort of functionality I originally envisioned. Thanks in advance for any responses.