Setting Alts on Clones

Unadept
06 Jan 2016, 13:13
Hey, All,

I've been asking for a lot of help recently, and I appreciate your assistance.

I've learned how to sequentially clone objects, and to do so without having to repeat the rules for each new object. Setting the item.alt for a known clone, like key1, is easy. I'm having trouble creating an alt for an unknown clone.

I have an attribute of player.stuff that's an integer. I would like, each time a clone of any object is created, to set the current player.stuff integer as an alt for that clone.

this.listalias = player.stuff + ": " + this.realname
this.alt = player.stuff
CloneObjectAndMove (this, player)
msg (this.realname + " added to cart.")
this.listalias = this.realname
this.alt = this.realname
IncreaseObjectCounter (player, "stuff")


This is what I have, as a script on an object type, where realname is an attribute on each object that I want to be the listalias of each item.

However, after I 'verb' the item in question, I can't seem to 'look at' either the original object or the clone using either the original name or the alt. I get this error, "Error running script: Cannot foreach over '7mm Longarm' as it is not a list".

I THINK what's happening is that it no longer recognizes item.alt as a list... but I don't know how to fix it.

Can you guys help me?

Thanks.

The Pixie
06 Jan 2016, 15:33
The alt attribute is a string list, not a string (unlike listalias, which is not a list), as you suspect. The easiest way to do it is to use the Split function:
this.alt = Split("this.realname", ";")

That said, you seem to be changing the original, not the clone (assuming this is in a script on the original). Perhaps like this:
copy = CloneObjectAndMove (this, player)
copy.listalias = player.stuff + ": " + this.realname
copy.alt = Split("this.realname;" + player.stuff, ";")
IncreaseObjectCounter (player, "stuff")
msg (this.realname + " added to cart.")

Unadept
06 Jan 2016, 17:32
Awesome, it was the Split function I was missing.

If the copy function lets me target the clone rather than the original, then that's great, that's a lot faster and cleaner. What I was doing was trying to change the original, clone it, then change it back.

Many Thanks

The Pixie
06 Jan 2016, 20:22
Sorry, I might have confused you there. "copy" is the name of a local variable, it is the copy of the original. The CloneObjectAndMove function returns an object, and that is assigned to this variable. The attributes are then set on that object.