(TADS3) Can I get the unique instance ID of an object?

Consider the following hypothetical code:

class MyThingy : Thing
  name = 'my thing';
  getMyID() { /*What goes here?*/ }
class MyActor: Actor
  name = 'my actor';
firstFred: MyActor 'Fred' 'fred' "You see Fred"
+ firstFredsThing : MyThing
secondFred: MyActor 'Fred' 'fred' "You see Fred"
+ secondFredsThing : MyThing

This creates two instances of MyThing - one inside firstFred and one inside secondFred. Both are identical in every way except for their location properties. If I test any of the following properties for the two MyThing’s, I’ll get the same exact string for both objects

firstFredsThing.name (which is ‘my thing’) will be identical to secondFredsThing.name (which is ‘my thing’)
firstFredsThing.location.name (which is firstFred’s name ‘fred’) will be identical to secondFredsThing.location.name (which is secondFred’s name ‘fred’)

Is there some sort of expression I can write in TADS for the getMyId() function in the code that will give a different string for firstFredsThing that is unique from secondFredsThing?

The reason this matters is that with my ongoing problem trying to make a system that allows ConvNodes to work in a library of classes you inherit from, rather than in top level user code, I just ran into this problem:

So if the code is used like the above example by the caller of the library, i end up with multiple convNodes with the same name value and that breaks the system. Ideally I’d like to have the constructor for my ConvNodes build their names as follows:

baseName = 'blackjack playing'
  name = baseName + ' ' +(some unique instance id goes here);

So that If the caller of my library tried making two generic actors that were both generic enough
that they had the same names, and that were both blackjack players, I would end up with two
ConvNodes that still have different names because their names would be something like this:
a ConvNode who’s name is something like:
‘blackjack playing 103010’
another ConvNode who’s name is something like:
‘blackjack playing 103521’
To force uniqueness.

The problem is that there doesn’t seem to be any way I’ve found to do the equivalent of this sort of C code thing:
sprintf( myUniqueId, “%p”, &myself );
I can’t get a unique ID for the current object reference. As long as two objects have identical properties, I don’t have a way to generate a value that is unique for each.

The closest I have found is the ‘&’ operator, but that only works on the properties within an object, not on the object itself.

You can use rand() to create a random alphanumeric string and assign that to the convNode’s name when it gets constructed.

See tads.org/t3doc/doc/sysman/tadsgen.htm#rand for details.

I did a similar thing to what you suggest except instead of rand() (which has the potential but rare possibility of generating the same ID number more than once) I made an ID incrimenter like so:

idPool : object
  lastId = 0
  next() { return ++lastId; }

so the first time I call idPool.next() I get a 1, the next time a 2, the next time a 3, and so on all the way up to max int.

The obvious realization I didn’t have is that I don’t need to associate the ID number with the actor. I just need a separate one per ConvNode. Who cares why or how a new ConvNode is being constructed - as long as one is, give it a new ID number.

But as I did this more I encountered the following discrepency in the documentation:

The class documentation for ConvNode says this:

(boldface mine)
Compare that to this, which is in the class documentation for Actor:

I suspect this whole thing about needing a separate ID may be untrue, and the documentation for ConvNode.name may be in need of an edit. Looking at the innards of how conversationManager builds the convNodeTab list, I think it is true that it’s acceptable to have two nodes named the same as long as they are in different actors.

This was changed a while back. According to the change log for version 3.0.10:

“Minor incompatibility warning: Each actor now has its own separate lookup table of ConvNode names. This means that you don’t have to worry about making ConvNode names unique globally - you only have to make sure that names are unique within a single actor’s set of nodes.”

From what you say, I imagine this change failed to be reflected in the comments for ConvNode.name.

Thanks. I started to suspect as much from looking at bits of the adv3 code but it would have taken a long time to completely reverse-engineer it all to verify for myself that this was true. It does make things easier for me to know it because if I can name my “I’m starting to deal cards now” node the same for all actors that have dealer behavior enabled, that also allows me to switch ConvNodes by that name without having to clumsily tack on an ID at the end every time I try to mention the rule name in the code.