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...