Overriding the travelBarrier

I’ve been working my way through the “assignment” in Chapter 4.5 in the Learning T3 manual. One thing I’m not satisfied with is overriding the travelBarrier-function. I’ve done this:

BicycleBarrier : VehicleBarrier
	explainTravelBarrier(traveler)
	{
		"You can not ride the old bicycle that way of course. ";
	}
;


+ OakTree: StairwayUp 'oak wooden tree' 'oak tree' "It is climbable. "
	travelBarrier = [BicycleBarrier, TrolleyBarrier]		
	canTravelerPass(traveler) { return !Bicycle.isIn(traveler); }
	explainTravelBarrier(traveler)
	{
	    "You certainly cannot ride the old bicycle up a tree! ";
	}
;

But whenever I try to ride up that tree I get: "You can not ride the old bicycle that way of course. "
I even looked in the example ‘Connectors.t’ for an answer to this, but it seems it does not work there either. The customized message is never displayed, just the message from BicycleBarrier.

What is missing here?

I’m not sure this is the problem, but are you attaching that to the travel connector correctly?

Untested, and my T3 is rusty, but I don’t think your explainTravelBarrier routine will be consulted when it’s directly in the OakTree object. You need to put the explanation in the TravelBarrier object, as that’s the routine that is going to be called.

That would be my first guess, anyhow.

In the event that you have bicycle barriers in several places and want different messages to appear, the TravelBarrier can sort out what needs to be printed, most likely by testing the value of me.getOutermostRoom().

I’m not sure what behavior you expect, but keep your eye on the condition also. “!Bicycle.isIn(traveler)” is not the same as “!traveler.isIn(Bicycle)” because the one is when you carry bicycle in hands and the other when you driving.

Oh, I see. In the example by Eric Eve you were stopped from climbing the tree while carrying the bike. If you on the other hand tried to ride the bike up the tree the ordinary VehicleBarrier function was carried out.

If I’m just allowed to tailor-suit certain messages in the VehicleBarrier function, I need to get the direction as well. “me.getOutermostRoom()” just returns the current room. How do I get the direction?

Are you really sure you can not check “canTravelerPass()” for conditions on if you are riding the bike or not? Somehow?

I mean if this code checks if you are carrying the bike and returns true if you are not:

canTravelerPass(traveler) { 
		return !Bicycle.isIn(traveler); 
	}

How then will this pseudo-code translate to tads3?:

canTravelerPass(traveler) { 
		if the player is riding the bike, return false.
	}

If it’s impossible I stick to the VehicleBarrier function… Just thought it would be kind of neat to be able to use it in canTravelerPass() for certain places.

Chapter 11.6 of Lerning T3 suggests something like this:

canTravelerPass(traveler) { return !traveler.ofKind(Vehicle); }

because when you are riding the bike, the actual traveler is the bike and not the player. (Bike is derived from Vehicle class, therefore the ofKind will return true for bike as a traveler.)

That was it! It works like a charm :slight_smile:
Thank you!

BicycleBarrier : VehicleBarrier
	explainTravelBarrier(traveler) {	"You can not ride the old bicycle that way of course. ";	};

+ OakTree: StairwayUp 'oak wooden tree' 'oak tree' 
	"It is climbable. "
	travelBarrier = [BicycleBarrier, TrolleyBarrier]
	canTravelerPass(traveler) { 
		if(Bicycle.isIn(traveler)) return nil;
		return !traveler.ofKind(Vehicle);
	}
	explainTravelBarrier(traveler)
	{
		if(traveler.ofKind(Vehicle)) 
		{
			"You can not ride the bike up the tree, silly!";
			exit;
		}
		"You can hardly climb the tree carrying the bicycle. ";
	};