• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Magistrix 1 · Aug 17, 2010 at 04:09 PM · errorsyntax-erroruce0001

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[i] = new Array(inventorySizeY);
}

}

function OnGUI() {

var texToUse : Texture2D; var currentInventoryItem : InventoryItem;

    if(PlayerGUI.doWindow)
    {
         for( var i = 0; i &lt; inventory.length; i ++ )
         {
             for( var k = 0; k &lt; inventory[i].length; k ++ )
             {
                texToUse = emptyTex;
                currentInventoryItem = inventory[i][k];

                 if( inventory[i][k] != null)
                 {
                     texToUse = currentInventoryItem.texRepresentation;
                 }

                 var it = GUI.Button( new Rect( offSet.x+k*(iconWidthHeight+spacing), offSet.y+i*(iconWidthHeight+spacing), iconWidthHeight, iconWidthHeight ), texToUse );


                 if (it)
                 {
                     if(texToUse == ItemTexture_1) 
                         {
                         Instantiate(ItemObject_1,transform.position,transform.rotation);
                         //This is the Problem (Without this line the Code is working):
                         delete InventoryItem;
                         }


                     if(texToUse == ItemTexture_2) 
                         {
                         Instantiate(ItemObject_2,transform.position,transform.rotation);
                         }

                  }
             }
         }
      }

}

function AddItem( item : InventoryItem ) {

for( var i = 0; i < inventory.length; i ++ ) {

 for( var k = 0; k &lt; inventory[i].length; k ++ )
 {

    if( inventory[i][k] == null )
     {
         inventory[i][k] = item;
         return;

     }
 }

}

}

function AddItem( worldObject : GameObject, texRep : Texture2D ) { var newItem = new InventoryItem();

newItem.worldObject = worldObject; newItem.texRepresentation = texRep;

AddItem( newItem ); }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Magistrix 1 · Aug 18, 2010 at 09:24 AM

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

 inventory[i][k]= null;

:) now it is working.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Wolfram · Aug 17, 2010 at 04:16 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Magistrix 1 · Aug 17, 2010 at 05:36 PM

I tried

delete currentInventoryItem;

and i tried

delete inventory[i][k];

before but without success.. I tried it again but no change in the error log.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Eric5h5 · Aug 17, 2010 at 08:12 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

help with UCE0001: ';' expected. Insert a semicolon at the end 3 Answers

Editing the jumppad from the 3rd person tutorial 2 Answers

Lerpz tutorial multiple errors.HELP!!!! 4 Answers

Scripting Error when drawing texture to custom window; What am I doing wrong? 1 Answer

Collision Detector script 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges