throw #object# error befuddlement

When using

throw #object#

as a command, i ask the script to check if the object is breakable

 if (HasAttribute(object, "breakable")) {
   destroy (object)
   msg ("<br>You throw the " + GetDisplayAlias (object) + " across the room and it   breaks as it lands.")
 }

from this example, can you tell why it might throw this error message?

Error compiling expression 'object':
RootExpressionElement: Cannot convert type 'element' to expression result of 'string'

Here is the whole command: (It's a bit jumbled from copy/pasting on post)

 <command name="throw">
    <pattern>throw #object#; toss #object#</pattern>
    <script><![CDATA[
	  if (HasAttribute(object, "throwable")){
            if (object.parent = player) {
             if (HasAttribute(player.parent, "nofloor")) {
               object.parent = player.parent.dropdestination
               ClearTurn
	       msg ("")
               msg ("You throw the " + GetDisplayAlias (object) + " and watch it fall out of sight.")
           }
           else if (HasAttribute(player.parent, "floorislava")) {
             ClearTurn
             destroy (object)
		     msg ("")
		     msg ("You throw the " + GetDisplayAlias (object) + " and watch it melt in the lava below.")
           }
           else if (HasAttribute(player.parent, "flooriswater")) {
             ClearTurn
             destroy (object)
		     msg ("You throw the " + GetDisplayAlias (object) + " and watch it sink into the water below.")
           }
           else {
             ClearTurn
			 if (HasAttribute(object, "breakable")) {
			   destroy (object)
			   msg ("<br>You throw the " + GetDisplayAlias (object) + " across the room and it breaks as it lands.")
			 }
			 else {
			   ClearTurn
			   object.parent = player.parent.dropdestination
		       msg ("<br>You throw the " + GetDisplayAlias (object) + " across the room.")
			 }
           }
	     }
         else {
           ClearTurn
		   msg ("")
		   msg ("You need to take the " + GetDisplayAlias (object) + " first.")
         }
	  }
	  else {
	    ClearTurn
	    msg ("<br>You can not throw " + GetDisplayAlias(object) + ".")
	  }
    ]]></script>
  </command>

if I remove the attribute breakable from the object the script works. So I assume the error comes from:

 else {
     ClearTurn
      if (HasAttribute(object, "breakable")) {
	 destroy (object)
	 msg ("<br>You throw the " + GetDisplayAlias (object) + " across the room and it breaks as it lands.")
			 }

The parameter passed to destroy is the name of the object, not the object itself.

Your code would also cause an error because you try to use GetDisplayAlias on the object to show a message after the object has already been destroyed.

You want:

 if (HasAttribute(object, "breakable")) {
   msg ("<br>You throw the " + GetDisplayAlias (object) + " across the room and it breaks as it lands.")
   destroy (object.name)
 }

Alternatively, you could use the function RemoveObject() instead of destroy(). This sets the object's parent to null, putting it out of reach of the player (it's floating in space, outside any room). In some cases this is advantageous because it guards against unexplained errors later on if an objectlist attribute somewhere contains a destroyed object.


I used RemoveObject(object) and it worked.

Any difference from RemoveObject(object.name)?

I also noticed that GetDisplayAlias (object) only prints the name while GetDisplayName (object) prints the name and adds it's prefix and suffix, which was a bit weird in the instance. (Just a note.)

Thanks for the assist mrangel


It's RemoveObject (object) or destroy (object.name). Using them the wrong way around will just give you an error.

Each has its own problems, unfortunately. In most cases, it's easier to remove objects rather than destroy them; but if you're removing large numbers of objects (like dozens of clones), having them all existing out there in space might start to impact your game's performance.


as mrangel alluded to:

if you make clones (extra/temporary Objects) or directly create your own Objects (extra/temporary Objects), during game play, then you likely want to destroy them, once you're done using them during game play

otherwise, the Objects are likely important Objects that you need for your game, and thus should just be "removed" (which just sets the Object's 'parent' Object reference/pointer Attribute to 'null', which means the Object simply is not contained within another Object, but instead the 'asl' GAME OBJECT is that Object's direct parent, the Object is being directly contained by the 'asl' GAME OBJECT), or the Object should be placed/moved/set to be within some other Object as storage, until you need to use it again


an Object contained by another Object:

<asl version="550">

  <game name="example_game">
  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">

    <attr name="parent" type="object">example_object_1</attr>

  </object>

</asl>

or (this is the same as the above --- the above is what is really happening):

<asl version="550">

  <game name="example_game">
  </game>

  <object name="example_object_1">

    <object name="example_object_2">
    </object>

  </object>

</asl>

using the 'RemoveObject' helper Function:

<asl version="550">

  <game name="example_game">

    <attr name="start" type="script">

      RemoveObject (example_object_2)

    </attr>

  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">

    <attr name="parent" type="object">example_object_1</attr>

  </object>

</asl>

or, setting the 'parent' Object reference/pointer Attribute to 'null' yourself:

<asl version="550">

  <game name="example_game">

    <attr name="start" type="script">

      example_object_2.parent = null

    </attr>

  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">

    <attr name="parent" type="object">example_object_1</attr>

  </object>

</asl>

or, using the 'set' helper Function to set the 'parent' Object reference/pointer Attribute to 'null':

<asl version="550">

  <game name="example_game">

    <attr name="start" type="script">

      Set (example_object_2, "parent", null)

    </attr>

  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">

    <attr name="parent" type="object">example_object_1</attr>

  </object>

</asl>

which does this:

An Object NOT contained within another Object (the 'asl' GAME OBJECT is the direct parent of the Object):

<asl version="550">

  <game name="example_game">
  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">
  </object>

</asl>

whereas 'destroy' actually DESTROYS the Object:

from this:

<asl version="550">

  <game name="example_game">

    <attr name="start" type="script">

      Destroy (example_object_2.name)

    </attr>

  </game>

  <object name="example_object_1">
  </object>

  <object name="example_object_2">
  </object>

</asl>

to this:

<asl version="550">

  <game name="example_game">
  </game>

  <object name="example_object_1">
  </object>

</asl>

Log in to post a reply.

Support

Forums