List not calling method

The first list item below is ignored (an empty line is output), and I’m not sure why.

topicResponse { if (condition) "Say something "; else thisList.doScript(); } thisList: StopEventList { [ &callAMethod, 'Some text', 'Different text.', 'Yet more text.' ] } callAMethod { incrementSomething(); "A Bunch of Text. "; } ;

If I instead name the object Foo and the first list item is Foo.callAMethod, it does the opposite: calling callAMethod before each iteration of the list.

How can I get the list to call callAMethod instead of returning a blank line?

In my testing, I get the same results you’re seeing. This is not a solution to your problem, but it’s an indication that the problem may be a library bug. According to the LRM:

You were attempting to use a function pointer. I attempted a workaround, replacing &callAMethod with ‘<>’. Again, this should be legal, but it doesn’t work either.

For reference, here’s a more complete test script:

[code]+ me: Actor
;
++ banana: Food ‘banana’ ‘banana’
"It looks yummy. "
;

  • bob: Actor ‘Bob’ ‘bob’
    "Good old Bob. "
    isProperName = true
    ;
    ++ bobConversing: ActorState
    isInitState = true
    ;
    +++ bananaTopic: AskTellTopic ‘banana’
    topicResponse {
    if (banana.isIn(me)) "Say something. ";
    else thisList.doScript();
    }
    thisList: CyclicEventList {
    [
    ‘<<bananaTopic.callAMethod()>>’,
    'Some text. ',
    'Different text. ',
    'Yet more text. ’
    ]
    }
    callAMethod {
    incrementSomething();
    "A bunch of text; something is now <>. ";
    }
    something = 0
    incrementSomething () {
    something = something + 1;
    }
    ;[/code]
    Here I’ve explicitly invoked bananaTopic.callAMethod rather than rely on the compiler to figure out what object is being implicitly referred to. I also (out of curiosity) switched to a CyclicEventList. This produces a new type of error:

With this code, callAMethod() is being invoked EVERY time the EventList is summoned, even though it shouldn’t be. I have no idea what’s going on. Hopefully someone wiser than I will be able to at least suggest a workaround that works.

Thanks, Jim. Do you know of any other efficient ways to have a conditional point to a list?

Jim, would page 141 of Learning TADS 3 help? Lower on that page Eric says: “…the elements of an EventList are evaluated far more frequently than you might expect (typically six times per turn), even though you only see one of them displayed. In this kind of case, you do need to enclose the embedded expressions in double-quoted strings using anonymous functions.” and suggest something like:

myList: ShuffledEventList
    [
        {: "The wind whistles in the trees; you have now noticed this <<++count>> times. "},
        {: "A <<one of>>starling<<or>>crow<<or>>pigeon<<or>>blackbird<<cycling>> suddenly takes flight. "}
    ]
    count = 0
;

Just eyeballing your code, the problem is that &callAMethod refers to thisList.callAMethod. However, you have callAMethod defined in the object that contains thisList. Try this (untested, I don’t have TADS 3 in front of me) code instead:

topicResponse { if (condition) "Say something "; else thisList.doScript(); } thisList: StopEventList { [ &callAMethod, 'Some text', 'Different text.', 'Yet more text.' ] callAMethod { incrementSomething(); "A Bunch of Text. "; } } ;

Looks like the experts solved the problem. Coolio!

Yep, that did the trick. Thanks experts!