Unexpected behavior when I try to override the default behavior of a custom action I defined

Hello! I’m learning TADS 3, trying to create a simple IF, following the official documentation (which is huge!)

I noticed a strange behavior that I’m unable to explain why it’s happening. I defined the action BreakWith in this way:

DefineTIAction(BreakWith)
	execAction()
	{
		"{You/He} break {that dobj/he}. ";
	}
;

VerbRule(BreakWith)
	('break' | 'destroy') dobjList 'with' singleIobj
	: BreakWithAction
	verbPhrase = 'break/breaking (what) (with what)'
;

and then I’m trying to override its default behavior in this way:

+ x: Thing 'x' 'x'
	"x is a thing"
	dobjFor(BreakWith)
	{
		preCond = [touchObj]
		verify() {  }
		action(){
			"test 1";
		}
	}
;

+ y: Thing 'y' 'y'
	"y is a thing"
	iobjFor(BreakWith)
	{
		preCond = [touchObj]
		verify() {  }
		action(){
			"test 2";
		}
	}
;

I’m expecting that break x with y will print “test 2test1”, but instead You break that. is printed (the default action, not the overriden action)

bonus strange thing, If I try to override an existing action, like CutWith, it works as I expect:

+ x: Thing 'x' 'x'
	"x is a thing"
	dobjFor(CutWith)
	{
		preCond = [touchObj]
		verify() {  }
		action(){
			"test 1";
		}
	}
;

+ y: Thing 'y' 'y'
	"y is a thing"
	iobjFor(CutWith)
	{
		preCond = [touchObj]
		verify() {  }
		action(){
			"test 2";
		}
	}
;

cut x with y correctly prints “test 2test 1”. Why is this happening? am I defining the action in the wrong way? I copied the code from the official documentation, I read that chapter like 5 times, but still I can’t find any error. any help?

thanks in advance guys!

1 Like

I think you want to change your action definition to look something like this:

DefineTIAction(BreakWith)
;

In other words, don’t override execAction(). The default library implementation of TIAction will then invoke the dobj and iobj handlers on the respective objects.

(Another way to put it is, make your BreakWith action look similar to the CutWith action.)

4 Likes

you just saved me! I can’t believe the solution was this simple… thank you very very VERY much!

why isn’t this mentioned in the official documentation? or did I missed it?

1 Like

It’s definitely in the docs🙂 Overriding execAction is for IActions…

1 Like