[I6] Changing the "name" of an Object after its creation

Sorry if that has been asked before, searching is a bit difficult when some things get ignored.

How to pull off changing the name of an Object?
Is that a job for parse_name? It seems to be the only real solution, but maybe “name” can be edited somehow, too.
I really just need to add one or two more terms to it after identifying the object.

Hmmm… Checking out the bubble class examples might help:



  Class   Bubble(10)
    with  short_name [;
              print (address) self.&name-->0, " ", (address) self.&name-->1, " bubble";
              rtrue;
          ],
          name '.size' '.colour' 'bubble' 'bubbles//p',
          description [; print_ret (The) self, " floats gently in the air."; ],
          create [;
              self.&name-->0 = random('tiny','small','regular','large','enormous');
              self.&name-->1 = random('red','green','blue');
              PronounNotice(self);
              move self to location;
              StartTimer(self, random(5));
              "You carefully blow ", (a) self, ".";
          ],
          before [ player_gone s c;
            Attack,Burst,Cut,Push,PushDir,Rub,Squeeze,Take,Taste,Tie,Touch,Turn,Wave:
              StopTimer(self);
              player_gone = (self notin location);
              s = self.&name-->0; c = self.&name-->1;
              Bubble.destroy(self);
              self.&name-->0 = s; self.&name-->1 = c;
              if (player_gone) rtrue;
              "With a gentle 'pop', ", (the) self, " bursts.";
          ],
          time_left 0,
          time_out [; <<Burst self>>; ];

firthworks.com/roger/informfaq/oo.html

In fact a little test seems to show that

self.&name-->0 = 'Sally'; 

Can replace the first entry in the list of names for an object when I call it in an “Initial” block, so it’ll probably work elsewhere as well.

Yes, thank you, that worked just right.
Just got to take care to use single quotes/apostrophe for the new value, right.
The compiler/source accepting double quotes is trappy.

Yeah, if you need an apostrophe, you should do something like

self.&name-->0 = 'brunette^s'

which will be “brunette’s” in game.

You can also add the name to the list of names by counting up your exisiting lists of names and popping it in after the last one:

name 'Sally','Girl','Woman',
...
...
self.&name-->3 = 'NewSally'

self.&name–>0 is ‘Sally’
self.&name–>1 is ‘Girl’
self.&name–>2 is ‘Woman’

then, when you’ve added another
self.&name–>3 is ‘NewSally’

Cool, thank you very much!

I wasn’t too sure if I could just add things at the end like that.
Initially I only skimmed the manual on that section, reading something about going beyond the boundaries of the array, and since I didn’t want to deal with that at the time, yeah :stuck_out_tongue:
Skipped it.
Going to study it more in depth next.

Maybe you can add some blanks to the name array… Not completely sure. Let me know how it works out :slight_smile:

You can indeed add some blanks! I’m trying to remember the example number now, but one of the DM4 examples uses this.

(Though parse_name is usually better once you start needing two or more blank name entries.)