Cloned Object in inventory isn't detected by object.name (Solved)

I have a command for cooking fish, ' cook #object# ', which first determines whether the object is cookable, then if there is an active cooker in the room, then what the object is, and what it should be replaced with.

ie, Carp becomes Cooked Carp, Beef Becomes Steak, etc.

Here is what I have:

if (not HasAttribute (object, "ISaCOOKABLE")) {
  msg ("You can't cook with this...")
}
else if (ListCount (FilterByAttribute (ScopeReachable(), "ISaCOOKER", true)) = 0) {
  msg ("There's nothing here for you to cook this with...")
}

This all seems to work fine, but this next bit runs silent, apparently doing nothing, and the items in inventory do not change.

else {
  if (object.name = "FISH_Carp") {
    RemoveObject (object)
    CloneObjectAndMove (FISH_Cooked_Carp, game.pov)
    msg ("You cook the Carp.")
  }
}

Im sure I have some little syntax error, but I do not know what it is... any ideas?


I managed to get it working by doing this:

  if (object.ISaCARP = true) {
    RemoveObject (object)
    CloneObjectAndMove (FISH_Cooked_Carp, game.pov)
    msg ("You cook the Carp.")
  }

Using an Attribute 'ISaCARP' instead of the object's Name, but if anyone can tell me how to use the name I'd rather not have unnecessary unique Attributes on every food item...


I have figured it out, because the item in inventory was a clone, I needed the object prototype.

if (object.prototype = FISH_Carp) {
  RemoveObject (object)
  CloneObjectAndMove (FISH_Cooked_Carp, game.pov)
  msg ("You cook the Carp.")
}

thats what i needed!


Yep :)

Note that this only works if you use CloneObject, not the basic clone function; and the prototype attribute will disappear if the original object is destroyed.

(Also, if you're working with multiple clones, it may be worth being aware of the difference between RemoveObject and destroy. RemoveObject (object) is the same as MoveObject (object, null) – it moves the object outside of all rooms, where the player can't see it. In large games with lots of clones, this may result in large save files because it's saving copies of all those objects. Whereas destroy (object.name) actually deletes the object, which is good for clones but may cause errors if you use it for any object whose name is mentioned in the code, or inside of a foreach loop. For clones, destroy is the more efficient option, but it can cause some weird and confusing bugs so might be reserved for more experienced programmers)


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums