TravelMessage

How can I have a room be connected to another room depending on a variable? Like, from room A “north” would normally lead to room B, but if variable X==1 then “north” would lead to room C.

(And how would I look up a question like this in the documentation? I always find myself completely helpless when opening the TADS 3 Bookshelf. The Inform 7 search window offers at least some help.

Thanks!

3 Likes

You can define the “north” property with the ternary operator:

north = x==1 ? loc1 : loc2
2 Likes

Like most things TADS, there are multiple ways to do this. For me, the most appropriate to a lot of my situations is making use of RoomConnector. Here is a lightly-edited sample from my code:

elevatorOnFloor : RoomConnector
    room1 = elevator
    room2 = elevator.atLobby ? lobby : hallIntersection
    canTravelerPass(traveler) { return (doorman.gotPasswd); }
    explainTravelBarrier(traveler) {
        "The doorman, ever so politely, will not let you pass
            without giving your pass phrase.  ";
    }
    /* invoked just PRIOR to the move */
    noteTraversal(traveler) {
        if (traveler == gPlayerChar)
            "The cage door makes a lot of noise as you get
                <<gActor.isIn(elevator) ? 'off' : 'on'>> the elevator.";
    }
;

In my example, there are only two floors, so the elevator Room contains the property atLobby. You could as easily assign room2 to any property/variable you cared to. If you need a TravelMessage-like reporting, you could use the noteTraversal method as above.

2 Likes

[dummy sentence so IF.org will stop editing me.]

CURSE YOU JZ! A THOUSAND CURSES ON YOUR FAST FINGERS, AND YOUR ELEGANT SOLUTIONS!!!

2 Likes

Apologies, @jjmcc , didn’t see that you were typing when I started my reply!
Note, @Grueslayer , that if you want both options to be TravelMessages you might want to do something like this

north = x==1  ? north1 : north2
north1: TravelMessage {->loc1 “msg” }
north2: TravelMessage {->loc2 “msg” }

unless loc1 and loc2 are themselves TravelMessages (which may not be desirable if there are multiple exits leading to them)

2 Likes

That worked! (With a little bit of tweaking but yeah - thanks!!!1)

2 Likes

Tangent but me and some others are working on improving this hehe!

2 Likes

Of course, for a multi-stories (storied ? story ?) elevator, north can point to a method containing an appropriate select…case.

Best regards from Italy,
dott. Piergiorgio.

1 Like