inform7

Synonyms in rules in Inform7 will not change?


To make code more readable in a current Inform7 project that contains special doors, I decided to create kinds of doors and things that are parts of the doors to backtrack which doors to open and close.
Background: A door can only be opened if it was previously manipulated by a thing called Mobitab and then unlocked by a Securitypass. So I created a kind of a thing called DoorpanelSM with a property manipulated (usually 0) and a property activated (usually 0). My code for the manipulation and unlocking of the doors looks like the following:

NOTE: The problem was narrowed down further. Edits are all the way to the bottom!

TürpanelSM is a kind of a thing. Sicherheitsausweis can be used with TürpanelSM. TürpanelSM has a number called activated. Activated of TürpanelSM is usually 0. TürpanelSM has a number called manipulated. Manipulated of TürpanelSM is usually 0.

Unlocking a TürpanelSM with Sicherheitsausweis is an action applying to two things.
Understand "use [Sicherheitsausweis] with [a TürpanelSM]" as unlocking a TürpanelSM with Sicherheitsausweis.

Manipulating a TürpanelSM with Mobitab is an action applying to two things.
Understand "manipulate [a TürpanelSM]" as manipulating a TürpanelSM with Mobitab.
Understand "use [Mobitab] with [a TürpanelSM]" as manipulating a TürpanelSM with Mobitab.

Instead of unlocking a TürpanelSM with Sicherheitsausweis:
    if TürpanelSM (called currentPanel) is part of a door and manipulated of the currentPanel is 0:
        say "Securitypass not accepted. You could try to manipulate the panel...";
    otherwise if TürpanelSM (called currentPanel) is a part of a door (called the parent) and activated of the currentPanel is 0:
        now the parent is unlocked;
        now the parent is open;
        now activated of the currentPanel is 1;
    otherwise if TürpanelSM (called currentPanel) is a part of a door (called the parent) and activated of the currentPanel is 1:
        now the parent is closed;
        now the parent is locked;
        now activated of the currentPanel is 0;
otherwise if TürpanelSM (called currentPanel) is a part of a door:
Instead of manipulating a TürpanelSM with Mobitab:
    if TürpanelSM (called currentPanel) is a part of a door and manipulated of the currentPanel is 0:
        now manipulated of the currentPanel is 1;
        say "Panel got manipulated";
    otherwise if TürpanelSM (called currentPanel) is a part of a door and manipulated of the currentPanel is 1:
        say "Panel was manipulated already.";

One door only works wonderful. However if I use two or more doors, the properties of the doorpanels defined appear to be global. I am certain that now activated of the currentPanel is 0; is not changing the property of the currentPanel but declares a global variable that is asked for on each of the conditions below. I am completely unable to find a way of correctly setting and getting the values of the panel I am asking for.

Small testprogram to show the problem (includes the above):

"TestsForSO" by geisterfurz007

Locker is a container.
Mobitab is in Locker.
Securitypass is in Locker.
Locker is in Hangar.

DoorpanelSM is a kind of a thing. Securitypass can be used with DoorpanelSM. DoorpanelSM has a number called activated. Activated of DoorpanelSM is usually 0. DoorpanelSM has a number called manipulated. Manipulated of DoorpanelSM is usually 0.

Unlocking a DoorpanelSM with Securitypass is an action applying to two things.
Understand "use [Securitypass] with [a DoorpanelSM]" as unlocking a DoorpanelSM with Securitypass.

Manipulating a DoorpanelSM with Mobitab is an action applying to two things.
Understand "manipulate [a DoorpanelSM]" as manipulating a DoorpanelSM with Mobitab.
Understand "use [Mobitab] with [a DoorpanelSM]" as manipulating a DoorpanelSM with Mobitab.

Instead of unlocking a DoorpanelSM with Securitypass:
    if DoorpanelSM (called currentPanel) is part of a door and manipulated of the currentPanel is 0:
        say "Securitypass not accepted. You could try to manipulate the panel...";
    otherwise if DoorpanelSM (called currentPanel) is a part of a door (called the parent) and activated of the currentPanel is 0:
        now the parent is unlocked;
        now the parent is open;
        now activated of the currentPanel is 1;
    otherwise if DoorpanelSM (called currentPanel) is a part of a door (called the parent) and activated of the currentPanel is 1:
        now the parent is closed;
        now the parent is locked;
        now activated of the currentPanel is 0.

Instead of manipulating a DoorpanelSM with Mobitab:
    if DoorpanelSM (called currentPanel) is a part of a door and manipulated of the currentPanel is 0:
        now manipulated of the currentPanel is 1;
        say "Panel got manipulated";
    otherwise if DoorpanelSM (called currentPanel) is a part of a door and manipulated of the currentPanel is 1:
        say "Panel was manipulated already.";

The idea is to do the following:

take Securitypass
take Mobitab
use Mobitab with TPTSM1 //which is the first doorpanel; manipulates the door
use Securitypass with TPTSM1 //opens the door
go west
use Mobitab with TPTSM2 //which would be the second doorpanel (to the northwest); says that the panel is already manipulated.

And I have no clue why... Any help is much appreciated!

EDIT: Investigating further, I used the showme command and found that the variables were properly changed on the first door, and they are both correctly at 0. However it is said that the panel is already manipulated despite the manipulated value beeing 0. Maybe the problem is connected to the currentPanel thing?
More EDIT: Actually it looks like exactly that... currentPanel seems to always be TPTSM1. My understanding was that it will change accordingly each time the rule is executed for any Doorpanel. How would I change the code to accomplish that?
Even more EDIT: So as said above (as it looks) the value of currentPanel appears to be fixxed after manipulating/unlocking it. However neither showme sees this thing nor can I use it elsewhere in the code. I know this behaviour only from parameters that are known only in functions as parameter. So this confuses me even more...


Solution

  • You're defining "currentPanel" too late. For example here there is no link to the door panel that the player is currently manipulating:

    if DoorpanelSM (called currentPanel) is part of a door ...
    

    It picks just some panel that exists in the game, which happens to always be TPTSM1.

    If you define it earlier, here:

    Instead of unlocking a DoorpanelSM (called currentPanel) with Securitypass:
    

    then it chooses the panel that is currently being unlocked. Alternatively you could use "noun" which is automatically the target of the current action.


    Unrelated side notes:

    Sicherheitsausweis can be used with TürpanelSM is unlikely to do what you meant it to do: it creates an adjective called "used with TürpanelSM" and does nothing else.

    Conversely, using number properties to track an object state is somewhat clunky, and adjectives are commonly used instead. So you'd define DoorpanelSM can be activated, test it with if currentPanel is activated and set it with now currentPanel is activated and now currentPanel is not activated.