Clone not inheriting verbs from original object

writtenhigh
09 Jan 2016, 04:40
I set up a custom eat verb on my blackberries, but the clones I create are not inheriting that custom verb, they inherit the default eat command. Even when I "delete" the eat command from the left hand panel after selecting to show library elements, it clones with the default eat command (so it's obviously not really being deleted.) Plus, I don't want to get rid of the default eat command, I just need additional scripts to run on the blackberries. How can I make it clone with the proper verb?

OurJud
09 Jan 2016, 18:22
I don't really understand what you're saying.

Are you saying 'eat blackberries' doesn't get the correct response? What response does it get?

[edit] Reading your post again, I see that this is some kind of cloning issue. It's not something I've ever experimented with, because I don't destroy my objects.

If that's what you're doing, then I have to ask why? Instead of destroy then clone, why destroy at all? If you just want the player to be able to pick and eat berries from a tree, indefinitely, then don't destroy them.

In truth, though, I'm still not clear on what you're trying to achieve.

The Pixie
09 Jan 2016, 20:13
What happens when you eat the original blackberries? Does it use the default eat then? I use types (and "edible" is a type) with verbs and clone them a lot, and it works okay.

writtenhigh
09 Jan 2016, 20:46
No. It uses the script when I eat the original blackberries. It just uses the default script for the cloned blackberries.

writtenhigh
09 Jan 2016, 20:49
<object name="blackberries">
<inherit name="editor_object" />
<alias>blackberries</alias>
<look>These berries look so purpley and juicy. God must be a rocket scientist to come up with this shit, man!</look>
<alt type="stringlist">
<value>blackberry</value>
<value>berries</value>
<value>berry</value>
</alt>
<displayverbs type="stringlist">
<value>Look at</value>
<value>Take</value>
</displayverbs>
<take />
<takemsg>Right on, man! You're taking some berries for later.</takemsg>
<dropmsg>I understand, man. Berries were never meant to go in pockets.</dropmsg>
<attr name="feature_edible" type="boolean">false</attr>
<eatmsg>Erhmahgherd! Mershed blackburrs!</eatmsg>
<inventoryverbs type="stringlist">
<value>Look at</value>
<value>Drop</value>
</inventoryverbs>
<listalias>Blackberry</listalias>
<ontake type="script">
</ontake>
<eat type="script">
CloneObjectAndMove (blackberries, player)
if (HasString(this, "eatmsg")) {
msg (this.eatmsg)
}
else {
msg (DynamicTemplate("Eaten", this))
}
if (HasInt(game.pov, "health")) {
game.pov.health = game.pov.health + this.eathealth
}
destroy (this.name)
MoveObject (blackberries1, blackberry_manor)
blackberries1.alias = "blackberries"
</eat>
</object>

writtenhigh
09 Jan 2016, 20:56
OurJud wrote:
If that's what you're doing, then I have to ask why? Instead of destroy then clone, why destroy at all? If you just want the player to be able to pick and eat berries from a tree, indefinitely, then don't destroy them.


Ultimately I'll probably be modifying it so that they can take multiple berries (maybe) or make some other stuff will happen when they eat them (definitely). And I was basing is off of the default eat script, and just modifying it to add the additional features I need, so that's the ultimate reason it's being destroyed.

jaynabonne
09 Jan 2016, 21:13
writtenhigh, the script you posted doesn't work, as you clone a new object named "blackberries1", but when you try to eat it, it still refers to "blackberries" in the script which no longer exists. If you change the usage of "blackberries" to "this", then it still fails on the second eat, as there is then no blackberries1 (since it has been destroyed at that point), since the clone is now called blackberries2.

The trick (as The Pixie has shown before) is that CloneObjectAndMove returns the new object.

This script will not give errors:

     <eat type="script">
new_object = CloneObjectAndMove (this, player)
if (HasString(this, "eatmsg")) {
msg (this.eatmsg)
}
else {
msg (DynamicTemplate("Eaten", this))
}
if (HasInt(game.pov, "health")) {
game.pov.health = game.pov.health + this.eathealth
}
destroy (this.name)
MoveObject (new_object, blackberry_manor)
new_object.alias = "blackberries"
</eat>

but I have to ask what you're trying to do. Why do you need to create a clone? If you're going to destroy the original after cloning, there is still only one blackberries object in the universe. Why not just reuse it?

Just because the blackberries are eaten from the player's point of view doesn't mean they have to be destroyed in your code!

Also other minor details: if you give the original blackberries the alias "blackberries", then clone picks it up for free without you having to assign it. Also, if you're going to be moving the object to blackberry_manor, why not just clone it there to begin with?

CloneObjectAndMove (this, blackberry_manor)


I still think you can save yourself all this cloning and deleting business by just moving the original blackberries to blackberry_manor when they're eaten.

OurJud
09 Jan 2016, 23:23
Glad it's not just me who's confused.

writtenhigh, can you explain exactly what it is you want to happen when a player eats the blackberries? LIke Jay before me, I'm totally failing to see why you want to clone them.

writtenhigh
10 Jan 2016, 04:56
jaynabonne wrote:writtenhigh, the script you posted doesn't work, as you clone a new object named "blackberries1", but when you try to eat it, it still refers to "blackberries" in the script which no longer exists. If you change the usage of "blackberries" to "this", then it still fails on the second eat, as there is then no blackberries1 (since it has been destroyed at that point), since the clone is now called blackberries2.


Yup. Part of what I was trying to figure out was how it was going to rename sequential clones of blackberries given the destruction.

jaynabonne wrote:The trick (as The Pixie has shown before) is that CloneObjectAndMove returns the new object.

This script will not give errors:

     <eat type="script">
new_object = CloneObjectAndMove (this, player)
if (HasString(this, "eatmsg")) {
msg (this.eatmsg)
}
else {
msg (DynamicTemplate("Eaten", this))
}
if (HasInt(game.pov, "health")) {
game.pov.health = game.pov.health + this.eathealth
}
destroy (this.name)
MoveObject (new_object, blackberry_manor)
new_object.alias = "blackberries"
</eat>


I code so little and so infrequently that I always forget that I can create objects with variables to refer to them. Thanks for that!

jaynabonne wrote:but I have to ask what you're trying to do. Why do you need to create a clone? If you're going to destroy the original after cloning, there is still only one blackberries object in the universe. Why not just reuse it?


There are multiple berries, now. That's just how my thought process works. Each iteration of code gets progressively more complex as I verify that the previous bit works as expected. Mostly because I'm a writer, and not a coder, so I expect no code I write to work correctly the first time. Now that I can clone and destroy things at will, it's gotten progressively more complex.

I'm mostly playing with the cloning option to learn it and see what all I can make happen with it, and how quest handles the clones themselves. Whatever I end up doing with the blackberries might not be the best use of it. I think ultimately each berry will have unique, randomly generated stats, and I can probably get by with moving things around and changing the stats on existing objects. We'll see.

Mostly I'm just coming up with random ideas and stretching myself to see what I can make happen. I don't have a set story yet, but it's coming together as I figure out how to code different things and figure out what Quest can do.

jaynabonne wrote:Also other minor details: if you give the original blackberries the alias "blackberries", then clone picks it up for free without you having to assign it.


That's another quirk that I couldn't figure out. I presumed that the "name" of the object would get passed as an alias... but I suppose many names will not end up being things that are nice for humans to read or write.

jaynabonne wrote:Also, if you're going to be moving the object to blackberry_manor, why not just clone it there to begin with?

CloneObjectAndMove (this, blackberry_manor)


I think that was from an iteration of the code where I was trying to figure out the naming convention for clones, and I wanted to move them out of the current room so I could see what all was going on. But yeah, not really necessary now.

Thanks again for all the help. It's starting to come back to me now that I'm back to a coding project instead of just a writing one. Because, let's be honest, most of the questions I've asked have been rookie questions I've just forgotten the obvious answers to.

Also, I'm assuming there's an advanced search option in the forums to exclude replies (now that I notice that there's an advanced button next to the search box.) Keep trying to search for stuff, but am bombarded by reply after reply from the same unhelpful threads...