Strange Error in JScript when using "delete"

Hi! I ve got a really strange Error in this Inventory Script when using the "delete" Statement. If i click the button it should throw out the item ( if there is any item in this slot) an should delete this item. So i thought i could use "delete InventoryItem;" and it worked! But after i restarted my PC i got this error when running the Script again : inv2.js(106,38): UCE0001: ';' expected. Insert a semicolon at the end. I tried everything ( at least i think so ) to get it to work again .... but without success. Has anyone a idea how to get this to work again ???


var inventory : Array;

var ItemObject_1 : GameObject; var ItemTexture_1 : Texture2D;

var ItemObject_2 : GameObject; var ItemTexture_2 : Texture2D;

public var emptyTex : Texture;

public var inventorySizeX = 4; public var inventorySizeY = 5;

var iconWidthHeight = 40; var spacing = 4;

public var offSet = Vector2( 100, 100 );

class InventoryItem { var worldObject : GameObject; var texRepresentation : Texture2D; }

function Awake() { inventory = new Array(inventorySizeX);

for( var i = 0; i < inventory.length; i ++ )
    inventory *= new Array(inventorySizeY);*
*<p>function OnGUI()* 
 *var texToUse : Texture2D;*
 *var currentInventoryItem : InventoryItem;*
 *for( var i = 0; i < inventory.length; i ++ )*
 _for( var k = 0; k < inventory*.length; k ++ )*_
 _*texToUse = emptyTex;*_
 <em>_currentInventoryItem = inventory*[k];*_</em>
 <em><em>_if( inventory*[k] != null)*_</em></em>
 <em><em>_*texToUse = currentInventoryItem.texRepresentation;*_</em></em>
 <em><em><em>_var it = GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );_</em></em></em>
 <em><em>_*if (it)*_</em></em>
 <em><em><em>*if(texToUse == ItemTexture_1)*</em></em></em> 
 <em><em>_*//This is the Problem (Without this line the Code is working):*_</em></em>
 <em><em>_*delete InventoryItem;*_</em></em>
 <em><em><em>*if(texToUse == ItemTexture_2)*</em></em></em> 
<em><em>_*<p>function AddItem( item : InventoryItem )*_</em></em>
<em><em>_*for( var i = 0; i < inventory.length; i ++ )*_</em></em>
 <em><em><em>_for( var k = 0; k < inventory*.length; k ++ )*_</em></em></em>
 <em><em><em><em>_if( inventory*[k] == null )*_</em></em></em></em>
 <em><em><em><em><em>_inventory*[k] = item;*_</em></em></em></em></em>
<em><em><em><em><em>_*<p>function AddItem( worldObject : GameObject, texRep : Texture2D )*_</em></em></em></em></em>
 <em><em><em><em><em>_*var newItem = new InventoryItem();</p>*_</em></em></em></em></em>
<em><em><em><em><em>_*`newItem.worldObject = worldObject;*_</em></em></em></em></em>
<em><em><em><em><em>_*newItem.texRepresentation = texRep;*_</em></em></em></em></em>
<em><em><em><em><em>_*<p>AddItem( newItem );*_</em></em></em></em></em>

InventoryItem is your class name you can't delete that. Use

delete currentInventoryItem;

(or whichever object you want to delete).

My guess is it didn't compile, even before the reboot, but one often overlooks these errors, and Unity will start normally - with the previous successfully compiled version of the script.

I tried

delete currentInventoryItem;

and i tried

delete inventory*[k];*
*<p>before but without success..*
*I tried it again but no change in the error log.</p>*

As far as I know there is no "delete" in Unityscript. If you're trying to remove an element from an Array, use RemoveAt.

hi ok thx for the quick answers. i fixed this problem with

 inventory*[k]= null;*
*<p>:) now it is working.</p>*