Possessive adjective on ThingState in TADS3/adv3?

Anyone know how to get possessive adjectives working with ThingState?

Here’s a silly example where there’s a pebble.

class Pebble: Thing '(small) (round) blue Alice\'s pebble*pebbles' 'pebble'
        "A small, round pebble.
        It is blue and belongs to Alice. <.reveal alice> "
        isEquivalent = true
;

startRoom: Room 'Void' "This is a featureless void.";
+me: Person;
+Pebble
        allStates = static [ defaultState, aliceState ]
        getState = (gRevealed('alice') ? aliceState : defaultState)
;
defaultState: ThingState
        stateTokens = static [ ]
;
aliceState: ThingState
        stateTokens = static [ 'Alice\'s', 'blue' ]
;

The pebble’s vocab includes the adjectives “blue” and “Alice’s”.

The pebble has two states. It starts out in defaultState, which has no stateTokens. It switches to aliceState when the pebble is examined.

aliceState has two stateTokens: “Alice’s” and “blue”.

When the game starts the adjective blue functions as expected: the adjective “blue” is excluded from the pebble’s vocabulary because it’s a token only present in an inactive state.

Void
This is a featureless void.

You see a pebble here.

>x blue pebble
You see no blue pebble here.

>x pebble
A small, round pebble.  It is blue and belongs to Alice.

>x blue pebble
A small, round pebble.  It is blue and belongs to Alice.

Great so far. But if we restart the game (or undo past the >X PEBBLE) the token “Alice’s” isn’t excluded from the pebble’s vocabulary due to being only on an inactive state:

Void
This is a featureless void.

You see a pebble here.

>x alice's pebble
A small, round pebble.  It is blue and belongs to Alice.

Anyone know the fix for this off the top of their heads?

2 Likes

I think the problem is that declaring the possessive adjective in the Thing’s vocabulary causes adjApostS to be set, and ThingState.matchName() doesn’t pay any attention to that. Which would mean it’s a bug/unsupported feature, and the solution is writing a replacement ThingState.matchName().

But I might be missing something obvious here.

2 Likes

Hm. Right, so it is matching via adjApostS, which is the form of the adjective without the apostrophe-S ending. In this case “Alice”.

Which means you’d have to add “Alice” to a ThingState’s stateTokens instead of “Alice’s”.

Buuuuut…unfortunately it looks like stateToken matching isn’t case-insensitive(?!)…so in order to work for both >x Alice's pebble and x alice's pebble you’d need to add both “Alice” and “alice” as stateTokens.

Is the fact that stateToken matching is case-insensitive just a bug, or is there some rationale that I’m overlooking?

2 Likes

Replying to myself again. I think this works, assuming there’s no reason why the checks against stateTokens shouldn’t be case-insensitive.

modify ThingState
        matchName(obj, origTokens, adjustedTokens, states) {
                local cur, i, len;

                len = adjustedTokens.length();
                for(i = 1; i <= len; i += 2) {
                        cur = adjustedTokens[i].toLower();

                        if(stateTokens.indexWhich(function(o) {
                                o = o.toLower();
                                if(o.endsWith('\'s'))
                                        o = o.substr(1, o.length() - 2);
                                return(o == cur);
                        }) != nil)
                                continue;

                        if(states.indexWhich({ x: x.stateTokens
                                .indexWhich(function(o) {
                                        o = o.toLower();
                                        if(o.endsWith('\'s'))
                                                o = o.substr(1, o.length() - 2);
                                        return(o == cur);
                                })
                        }) != nil)
                                return(nil);
                }

                return(obj);
        }
;

This allows:

aliceState: ThingState
        stateTokens = static [ 'Alice\'s', 'blue' ]
;

…to handle the possessive token the same as other tokens.

2 Likes