ShuffleEventList failing with index out of range exception

Still working through Learning TADS 3, getting great value out of it. Many thanks for the book(s) and for the response to my rookie questions on this forum.

I have another one.

I have implemented a character, a street person standing on a corner holding a handwritten poster.

I have an EventShuffleList of descriptions…

    stateDesc = "<<eventList>>"
    eventList = 
    [ 
        'The unkempt man leaned his back to the lamppost, the tattered
        cardboard poster held to his chest. ',

        'The disheveled man continued to peer steadily at 
        Harry, waving the tattered cardboard from side to side over his
        chest. ',

        'Harry felt uncomfortable in the glare of the roughly 
        dressed man with the cardboard poster that could barely be read. '
    ];

This works fine, at each “look” command a different description is displayed.

But once the poster is read, I want a different shuffle list to be used. When I implement the following code, though, I get an index out of range exception whenever I enter the location where the street person is standing…

  • streetPersonStanding: ActorState, ShuffledEventList
    {
    stateDesc = “<>”
    afterAction()
    {
    if(gRevealed(‘posterText’))
    {
    eventList =
    [
    'The unkempt man leaned his back to the lamppost, the tattered
    cardboard poster held to his chest. ',

                      'The disheveled man continued to peer steadily at 
                      Harry, waving the tattered cardboard from side to side over his
                      chest. ',
    
                      'Harry felt uncomfortable in the glare of the roughly 
                      dressed man with the cardboard poster that could barely be read. '
                  ];
             }
             else
             {
                  eventList = 
                  [ 
                      'The unkempt man leaned his back to the lamppost, the tattered
                      cardboard poster in his hand at his side. ',
    
                      'The disheveled man cast his gaze across the street,
                      the poster at his side. ',
    
                      'The homeless man waved his poster at
                      passing traffic. '
                  ];
             }
        }
    

    }

There is always a defined event list, one list if/else the other. I’ve tried various alternates to afterAction(), but I can’t get the event list initialized on entry to the room.

I think there is an acceptable alternative—implement before and after streetPersonStanding states—but I think it would be a bit more elegant to have it all in one actor state.

Jerry

Take a look at section 8.3 of Learning TADS 3. It appears to me (my T3 being very rusty) that you’re trying to define the eventList property on the fly. I don’t think you can do that. But there’s bound to be a way to create two separate eventLists during compilation, and then direct doScript() to one or the other depending on the value returned by gRevealed().

stateDesc needs to call doScript(), not eventList. ‘stateDesc = “<>”’ tells TADS to print the entire list, which isn’t what you want (and which TADS doesn’t know how to do anyway). This seems to work, assuming that this isn’t the first room you enter. (If it is the first room, you need to make sure that eventList already has a list in it when the game starts. At the moment, eventList is empty until after the player makes their first move.)

[code]+ streetPersonStanding: ActorState, ShuffledEventList
{
stateDesc = “<>”
afterAction()
{
if(gRevealed(‘posterText’))
{
eventList =
[
'The unkempt man leaned his back to the lamppost, the tattered
cardboard poster held to his chest. ',

                    'The disheveled man continued to peer steadily at 
                    Harry, waving the tattered cardboard from side to side over his
                    chest. ',

                    'Harry felt uncomfortable in the glare of the roughly 
                    dressed man with the cardboard poster that could barely be read. '
                ];
           }
           else
           {
                eventList = 
                [ 
                    'The unkempt man leaned his back to the lamppost, the tattered
                    cardboard poster in his hand at his side. ',

                    'The disheveled man cast his gaze across the street,
                    the poster at his side. ',

                    'The homeless man waved his poster at
                    passing traffic. '
                ];
           }
      }
}[/code]

However, updating the list every time you take an action isn’t very efficient. I would do it this way:

[code]+ streetPersonStanding: ActorState, ShuffledEventList
{
stateDesc = “<>”
eventList
{
if(gRevealed(‘posterText’))
{
return
[
'The unkempt man leaned his back to the lamppost, the tattered
cardboard poster held to his chest. ',

                    'The disheveled man continued to peer steadily at 
                    Harry, waving the tattered cardboard from side to side over his
                    chest. ',

                    'Harry felt uncomfortable in the glare of the roughly 
                    dressed man with the cardboard poster that could barely be read. '
                ];
           }
           else
           {
                return 
                [ 
                    'The unkempt man leaned his back to the lamppost, the tattered
                    cardboard poster in his hand at his side. ',

                    'The disheveled man cast his gaze across the street,
                    the poster at his side. ',

                    'The homeless man waved his poster at
                    passing traffic. '
                ];
           }
      }
}[/code]

Any property can be rewritten as code that returns a value instead. For instance, “myProperty = nil” is the same as “myProperty() { return nil; }”. And in most cases you can take advantage of that to have the property change depending on the game state - for instance, varying which list you use for an EventList.

(Let me know if that’s not clear and I’ll try to explain it better. I only just got up and I haven’t finished my coffee yet…)

Emily:

Very clear, tried it, it works. Thanks.

Jerry