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'
construct()
{
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.