Runtime TravelConnectors TravelDesc Issue

So I’m playing around with runtime object creation, including things like TravelConnectors, while arguably not needed it’s still fun to tinker with, I’ve run into an issue however.

pleasureGarden: Room 'The Pleasure Garden'
    "A room for breaking things."
    
    intendedNorthDir = pGarden2
   
    north()
    {
    if (intendedNorthDir.ofKind(Room))
        {
    connector = new TravelConnector();
        connector.destination = intendedNorthDir;
        connector.travelDesc = {: "You travel" };
        pleasureGarden.north = connector;
            //you can use travelvia here but that's not needed right now

        }
    }
   
;

The movement part appears to work, however displaying the TravelDesc is not something I seem to be able to get to display… I feel like I’m missing something painfully obvious here but I really am not sure what. Any help is appreciated!

1 Like

Are travelDescs required to be anonymous functions? I thought they were just ordinary “” strings.

when runtime created something you can’t use ““ strings as far as I know.

for example

connector.travelDesc = “You Travel!”;

you can’t do this because ““ acts as shorthand that basically says ‘display text’, it works when statically defined due to templates, I believe(?)

But yeah, that’s why.

1 Like

When you’re assigning a method like that use setMethod(). Example:

#charset "us-ascii"
#include <adv3.h>
#include <en_us.h>

startRoom: Room 'Void' "This is a featureless void. ";
+me: Person;

northRoom: Room 'North Room' "This is the room to the north. "
        south = startRoom;

versionInfo: GameID;
gameMain: GameMainDef initialPlayerChar = me;

DefineSystemAction(Foozle)
        execSystemAction() {
                local conn;

                conn = new TravelMessage();
                conn.destination = northRoom;
                conn.setMethod(&travelDesc, { : "You travel, dynamically. " });
                startRoom.north = conn;

                defaultReport('Bingo-bango, you can now go north...o. ');
        }
;
VerbRule(Foozle) 'foozle' : FoozleAction verbPhrase = 'foozle/foozling';

Transcript:

Void
This is a featureless void.

>n
You can't go that way.  There are no obvious exits.

>foozle
Bingo-bango, you can now go north...o.

>n
You travel, dynamically.

North Room
This is the room to the north.

>

A couple things to note:

  • setMethod() is used to assign travelDesc. There are a couple other ways to do this. If I have a bunch of these sorts of things I’ll declare a subclass with a custom travelDesc that displays some other property, call it customTravelDesc, and then assign that property, customTravelDesc, on individual instances.
  • You don’t want a bare TravelConnector; the travelDesc stuff is defined on TravelMessage rather than TravelConnector directly.
  • Related to the above, depending on what you’re trying to do (and if you have a bunch of NPCs who might be moving) you might want to handle this via noteTraversal()/explainTravelBarrier()/canTravellerPass() and so on.
  • I use a lot of itemized lists when explaining things.
3 Likes

Thank you! I was literally just coming back to say that

setMethod()

was the solution!

2 Likes