SenseRegion Description Order [Adv3Lite]

So, not to be too picky or anything, but would anyone happen to know how to set the order of remote descriptions in a SenseRegion?

I have a few Rooms in a SenseRegion, and when things are being listed off, I would like to have specific Rooms have a specific order when this happens.

Let’s say I have a Room called “The Hills”, another called “The Sanctuary”, and another called “The Barn”. If my character currently stands on a Room called “The Balcony”, which shares a SenseRegion with the previous 3 rooms, then how would I force the game to list the connected locations using an order of Barn, Hills, and Sanctuary every single time the player does a >LOOK AROUND action?

(This example is more general; the specific use case I have is a bit harder to explain, but would work the same way.)

It doesn’t break my project if this is impossible, but it would be really nice, just for neatness reasons.

1 Like

I just do it by hand rather than using a SenseRegion. If the player is standing on the balcony, I code the room description itself to refer to anything I want the player to be able to interact with (or even see) in the garden. I then add Distant objects to the balcony’s contents as needed, so the player can refer to them.

I had a look through the manual and didn’t see an obvious way to do what you’re describing, but it’s not entirely clear to me what you mean by “when things are being listed off.” If you want the library to automagically add “In the garden you can see a rusty water tank” to the room description when the player is on the balcony, I wouldn’t know how to do that, especially as the rusty water tank is likely to be a Fixture (and thus not listed following the garden’s desc().

As a first approximation, you might try listing the rooms[] of the SenseRegion in the desired order. And if it’s something in the garden that is not a Fixture, that would be tricky, depending on how many movable things are in your game, but you may find the sightSize property useful.

1 Like

So, if I may shed some light on some admittedly-strange specifics: I have a bunch of objects that the player can interact with. I then have a series of “distance brackets” represented by Rooms in a SenseRegion, so that objects at different distances have different levels of detail, different kinds of interactivity, and are described a little differently in the list. As objects get closer or further away, they will be moved into different Rooms, so that looking around gives the player an update on how far everything is at that time, and allows the player to rethink how they might interact with the objects.

I was hoping I could have the rooms listed off according to distance, because it’s weird if the 0-200 meter distance is first, then the 750-1250 meter distance is next, followed by backdrop objects (which also change), and finally the 200-750 meter distance objects are described at the end.

I’m also using a Room for a distance bracket because then I can assign nuanced values and behaviors to each one, instead of making every nuance be handled by every individual object. It’s always simpler to group together similar behaviors, instead of re-implementing them in every possible case. I guess I mean it’s a refactoring practice.

This is absolutely how I usually handle this situation, and it’s a very clean and elegant solution. This long-distance interactivity problem, however, has given me a bit of an edge-case.

I might wind up modifying some functionality of the SenseRegion code to introduce some kind of sorting method, when desired. Was just checking in to see if anyone knows how to do this without getting surgical.

1 Like

Okay, I figured it out. I’ll post my code here for anyone who needs it in the future!

modify Room {
    // Affects the order of listed rooms in a SenseRegion.
    // Higher values will be sorted last.
    // It's recommended to set the lowest bias to 1, in keeping
    // with the convention of array indices, as any Rooms which
    // were still "nil" will be set to 0, if sorting occurs.
    remoteSortBias = nil
}

modify SenseRegion {
    // This is the method that does the initial connecting before play.
    // Because of how SenseRegions can overlap, any room that requests a
    // sorting bias will enforce it on any other connected rooms.
    setFamiliarRooms() {
        inherited(); // First, work as intended

        // Determine if sorting is necessary
        local isSortingNecessary = nil;
        foreach(local rm in roomList) {
            if (rm.remoteSortBias != nil) {
                isSortingNecessary = true;
                break;
            }
        }

        // If sorting is necessary, then do so:
        if (isSortingNecessary) {
            foreach(local rm in roomList) {
                rm.visibleRooms = sortBiasInRoomSubList(rm.visibleRooms);
                rm.audibleRooms = sortBiasInRoomSubList(rm.audibleRooms);
                rm.smellableRooms = sortBiasInRoomSubList(rm.smellableRooms);
                rm.talkableRooms = sortBiasInRoomSubList(rm.talkableRooms);
                rm.throwableRooms = sortBiasInRoomSubList(rm.throwableRooms);
                rm.linkedRooms = sortBiasInRoomSubList(rm.linkedRooms);
            }
        }
    }

    // Every room can have wildly-different connection lists
    // for the various senses, so to accommodate this, we must
    // perform checks and sorts per list, per room.
    // This method is meant to handle this in a refactored way.
    sortBiasInRoomSubList(roomSubList) {
        // Do not interact with nil lists
        if (roomSubList == nil) return nil;
        // Do not sort lists shorter than 2 elements
        if (roomSubList.length < 2) return roomSubList;

        // Adjust any would-be non-participants
        foreach(local rm in roomSubList) {
            if (rm.remoteSortBias == nil) rm.remoteSortBias = 0;
        }

        return roomSubList.sort(nil, { a, b: a.remoteSortBias - b.remoteSortBias });
    }
}
2 Likes

I’ll take a look at adding something like this to the adv3Lite library for the 1.6 release, since I can see that there may be other situations in which you might want the remote room contents to appear in a certain order. My initial thought is that it might be possible to use the existing listOrder property (which Room inherits from Thing but doesn’t use) and define a new remoteListOrder(pov) method which returns the Room’s listOrder by default but can be used to define different list orders from different points of view within a SenseRegion, but I’ll need to look at this more closely.

2 Likes