Clone Object and then Destroy Clone [SOLVED]

So I want to clone and object and move it to a room and then afterward if the player performs a certain action I want to destroy it. I tried this...

x = CloneObject (fresh_water)
RemoveObject (x)

But it didn't work. Even though this does...

 x = CloneObject (fresh_water)
MoveObjectHere (x)

Any ideas?

Anonynn.


RemoveObject should work. Do you get an error message? That said, it does not really destroy the object, just sets its parent to null, which has the same effect and is quicker.


RemoveObject does not work---no error pops up, but it doesn't remove the Object either.

But I've noticed a strange ...something...happening when using an "Openable/Closable" container. On the Switchable Tab "After switching on the object:" and "After switching off the object:" Quest doesn't always work properly (which is what this script is written on). I know something is wonky with it because I had another Object, openable and closeable curtains. But Quest, wasn't recognizing isopen=True and isopen=False and kept saying the curtains were perma-closed.

Maybe I need to move the code to a verb instead?


are you sure you don't have some sort of tag conflict going on, which is confusing Quest as to which object you are acting on?


Pretty sure. I only had a short message, a flag and the isopen scripting on the curtains --- and when I moved the same code to a verb the scripting worked just fine.

I still need to figure out why the destroy object isn't working. I'm going to experiment with making it a verb and let you guys know how it goes. Then we'll know whether or not it's a problem with the Openable/Closeable thing.


Why not just move the object to another room that the player cannot reach???


I feel like if the RemoveObject isn't working properly then moving it to another room wouldn't either. Although, I haven't tried.

UPDATE:
That didn't work either

Here's the code in case it helps.

After "switching on"...

msg ("<br/><font color= \"70edf5\">You turn on the faucet and fresh water comes pouring out.</font color><br/>")
x = CloneObject (fresh_water)
MoveObjectHere (x)
gh_sink.flag = True

And "switching off"..

msg ("<br/>You turn off the faucet. {once:What a good guest!}<br/>")
MoveObject (fresh_water, Part 1)
gh_sink.flag = False

This didn't work either...

After "switching off"...

msg ("<br/>You turn off the faucet. {once:What a good guest!}<br/>")
RemoveObject (fresh_water)
gh_sink.flag = False

I = stumped. I'm going to try moving this to a verb to see if it fixes the problem. If it does --- that could mean a potential conflict error in Quest "Openable/Closeable" feature, I think.


UPDATE AGAIN:

So the same code in the verb versions, didn't work in removing the Fresh Water object either, although the game does now acknowledge that the object is getting turned off and on. Still can't figure out how to remove the Clone though.


I presume that the 'MoveObjectHere' Function is a custom function that takes an 'Object' Argument/Parameter and puts/moves that 'Object' inside of some set 'Object/Room Object', is this correct? (something like the below)

<function name="MoveObjecthere" parameters="moving_object_parameter">
  moving_object_parameter.parent = NAME_OF_YOUR_DESTINATION_OBJECT
</function>

x = CloneObject (fresh_water)
RemoveObject (x)

this just merely sets the CLONE_OBJECT's 'parent' Object Attribute to 'null', which effectively takes it out of any Objects (and moves/puts it directly into the 'asl' tag block)

your original 'fresh_water' Object remains in the room it is in

for example:

<object name="room">
  // <attr name="parent" type="object">null</attr>
  <object name="player">
    // <attr name="parent" type="object">room</attr>
  </object>
</object>

// RemoveObject (player)

// now, the code would be changed (look like) to this:

<object name="room">
  // <attr name="parent" type="object">null</attr>
</object>
<object name="player">
  // <attr name="parent" type="object">null</attr>
</object>

// -------------------------

// or

<object name="room">
  // <attr name="parent" type="object">null</attr>
</object>
<object name="player">
  // <attr name="parent" type="object">room</attr>
</object>

// RemoveObject (player)

// now, the code would be changed (look like) to this:

<object name="room">
  // <attr name="parent" type="object">null</attr>
</object>
<object name="player">
  // <attr name="parent" type="object">null</attr>
</object>

x = CloneObject (fresh_water)
MoveObjectHere (x)

this, assuming my guess about the 'MoveObjectHere' Function, just moves the CLONE_OBJECT to whatever is the DESTINATION_ROOM defined in the Function.

your original 'fresh_water' Object remains in the room it is in


if you're cloning your 'fresh_water' repeatedly.... DO NOTE: it creates a different CLONE Object each time: fresh_water1, fresh_water2, fresh_water3, fresh_water4, etc etc etc

so, maybe you're removing 'fresh_water5' CLONE, but not all the other 'fresh_water#' CLONES


also, note that:

x = CloneObject (NAME_OF_OBJECT)

the 'x' is just a (local) Variable VARIABLE, so if you have another 'x = CloneObject (NAME_OF_OBJECT)' elsewhere in your game, it's its own/different 'x' and a different/new CLONE as well.

if you want to globally store your CLONE OBJECT, you got to use a (global) Attribute VARIABLE, for example:

// somewhere:
game.x = CloneObject (NAME_OF_OBJECT)

// elsewhere:
MoveObjectHere (game.x)

// again, (a different), elsewhere:
RemoveObject (game.x)


so... maybe you wanted something like this?

(I replaced your 'x' Attribute Name with something more descriptive: 'fresh_water_clone_object_attribute')

// after switching on:

msg ("<br/><font color= \"70edf5\">You turn on the faucet and fresh water comes pouring out.</font color><br/>")
game.fresh_water_clone_object_attribute = CloneObject (fresh_water)
MoveObjectHere (game.fresh_water_clone_object_attribute)
gh_sink.flag = True

// and switching off:

msg ("<br/>You turn off the faucet. {once:What a good guest!}<br/>")
MoveObject (game.fresh_water_clone_object_attribute, Part 1) // unless you did want to move your original 'fresh_water' Object, and not the CLONE...
gh_sink.flag = False

// after switching off:

msg ("<br/>You turn off the faucet. {once:What a good guest!}<br/>")
RemoveObject (game.fresh_water_clone_object_attribute) // again, I assuming you went to remove your CLONE, and not your original 'fresh_water' Object
gh_sink.flag = False

Are you cloning the prototype, but the moving/removing the prototype, rather than the clone, so the clone is still there? the switch off code looks to remove the prototype:

msg ("<br/>You turn off the faucet. {once:What a good guest!}<br/>")
RemoveObject (fresh_water)
gh_sink.flag = False

I'm not sure. I'm doing...

x = CloneObject (fresh_water)
MoveObjectHere (x)

So if I'm removing a prototype than the remove code is definitely wrong. It needs to remove the clone. I was thinking perhaps doing a...RemoveObject (fresh_water.alias) but I'm sure the game would throw an string-element error. Or maybe MoveObject (fresh_water.parent)

We need a RemoveCloneObject or RemoveObjectAlias. LOL! :P


Nope, it's not a custom function, HK. Least as far as I know, it's just the built in "MoveObjectHere" (to current room the player object is in). And yup, I've been learning all sorts of things about "null" states lately! I know the answer is a simple one right on the tip of my tongue, like...moving the Object back to it's parent object (where the item is stored), but I just can't think of the right command.


Probably the best way in this case (i.e., where the clone will not be moved, so remains linked to the room) is to save the clone as an attribute of the room or some permanent object in it:

x = CloneObject (fresh_water)
MoveObjectHere (x)
gh_sink.clone = x

Then later you can use that to destroy it:

RemoveObject(gh_sink.clone)

the problem is that each CLONE OBJECT is given a contigious number onto its name

thus there's only two ways of getting at that CLONE OBJECT:

  1. store the CLONE OBJECT into an 'Object' Attribute:

game.fresh_water_clone_object_attribute = CloneObject (fresh_water)

and then you can use that Attribute for whatever you want to do with that Clone OBJECT, for example:

RemoveObject (game.fresh_water_clone_object_attribute)

  1. you'll have to iterate through all of the Objects in the Object containing your CLONE OBJECT and check if one of those Objects match up with your desired CLONE OBJECT, for example (pretending our desired CLONE OBJECT is in our inventory: inside of the 'player' Player Object):
<object name="player">

  // your original Object:
  <object name="fresh_water">
  </object>

  // your cloned/clone Objects (for this example, pretending, as I still not used a Clone yet, so I don't know how it concatenates the contigious number onto their names, lol: as in just the number or underscore and then the number, and whether the number starts at 0 or 1 or 2, lol):

  <object name="fresh_water_2">
  </object>
  <object name="fresh_water_3">
  </object>
  <object name="fresh_water_4">
  </object>
  <object name="fresh_water_5">
  </object>
  <object name="fresh_water_6">
  </object>

</object>

foreach (object_variable, ScopeInventory()) {
  if (object_variable.name = "fresh_water_4") { // let's say our desired clone object is: 'fresh_water_4'
    // scripting/action(s), for example:
    object_variable.drink // let's say that the 'drink' Verb/Script-Attribute itself does NOT remove the object, thus we do so below:
    RemoveObject (object_variable) 
  }
}

// and the resulting effective code would look like this:

<object name="player">

  // your original Object:
  <object name="fresh_water">
  </object>

  // your clone/cloned Object(s):
  <object name="fresh_water_2">
  </object>
  <object name="fresh_water_3">
  </object>
  <object name="fresh_water_5">
  </object>
  <object name="fresh_water_6">
  </object>
</object>

// the removed CLONE Object:
<object name="fresh_water_4">
</object>

Thanks guys :D


Log in to post a reply.

Support

Forums