String pointers in TADS3

I vaguely remember pointers being supported in TADS3 but documentation is sparse and seems to only cover function pointers, so I thought I’d post my use case here.

Let’s say I have a “global” string variable somewhere, maybe a message I’d like to use in multiple places.

myGlobal
    fooMsg = 'bar baz '
;

myObj : Thing
    cannotTakeMsg = &myGlobal.fooMsg // How do I do this?
;

The idea is that I could change the string later and all references to it would also update. Essentially, I need to use a C-style string pointer. Is this possible in TADS3?

Have you tried simply losing the ampersand? The cannotTakeMsg should re-evaluate every time it’s accessed, so if you change the global the takeMsg should reflect it, unless I’m misunderstanding what you’re asking…

Is there some reason you don’t want to just put it in playerActionMessages where most of these kind of messages live? Something like:

modify playerActionMessages
        cantWhateverHere = '{You/he} can\'t do that here. '
        cantWhateverObj(obj) { return('{You/he} don\'t do that to the <<obj.theName>>. '); }

;

Having done that, you can do things like

     action() { defaultReport(&cantWhatever); }

Or

     action() { defaultReport(&cantWhateverObj, self); }

But if you really want the messages to live in their own object, you can do something like:

myMsg: object
        fooMsg = 'foo bar '
;
pebble: Thing 'small round pebble' 'pebble'
        "<<globalMsg>>"
        globalMsg = (myMsg.fooMsg)
;

A little complete working example of the above:

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

modify playerActionMessages
        cantWhateverThat(obj) { return('{You/he} can\'t do that to the <<obj.theName>>. '); }
;

myMsg: object
        fooMsg = 'foo bar '
;

startRoom:      Room 'Void'
        "This is a featureless void. "
;
+me:    Person;
+pebble: Thing 'small round pebble' 'pebble'
        "<<globalMsg>>"
        globalMsg = (myMsg.fooMsg)
        dobjFor(Take) {
                verify() { illogical(&cantWhateverThat, self); }
        }
;

versionInfo:    GameID
        name = 'sample'
        byline = 'nobody'
        authorEmail = 'nobody <foo@bar.com>'
        desc = '[This space intentionally left blank]'
        version = '1.0'
        IFID = '12345'
;
gameMain:       GameMainDef
        initialPlayerChar = me
;

Transcript:

Void
This is a featureless void.

You see a pebble here.

>x pebble
foo bar

>take pebble
You can't do that to the the pebble.