- Home /
Insert semicolon at the end when theres already one?
// LootableObject.js
// Make the GameObject "Lootable".
// This script will
// Attach this script to any GameObject that is "Lootable"
#pragma strict
private var theInventoryItem : InventoryItem; // The current contents of this lootable object
private var thisLootableItem : GameObject; // A reference to this instance of this script
private var clicked : boolean; // Trap for creating the current contents only once
private var canLoot : boolean; // Boolean to control TestDistance.
private var playerTransform : Transform; // A reference to the Player Transform
private var thisTransform : Transform;
var itemName : String;
var itemIcon: Texture2D;
private var Inventory;
function Start ()
{ // Setup the initial states of the variables
//itemName = the object name
itemName = this.gameObject.name;
//itemIcon will get selected in Unity
//itemDescription as well
var theInventoryItem = new InventoryItem();
//Init thhe inventory item
theInventoryItem.itemName = itemName;
theInventoryItem.itemIcon = itemIcon;
thisTransform = this.transform;
playerTransform = GameObject.FindWithTag("Player").transform;
(thisLootableItem = this GameObject;)
clicked = false;
}
function OnMouseDown()
{
Loot ();
}
function Loot ()
{
if (!clicked)
{ // If not yet clicked, check Loot Table
clicked = true;
}
//Add the item to the inventory
Inventory.AddItem(theInventoryItem);
theInventoryItem = null; //Set it to null
//Destroy the game object
Destroy(this.gameObject);
}
Now this is a code for a GUI inventory. This is the item code. There`s an error that says I need a semicolon at the end of the line in parentheses. There`s already one there! Btw I`m new to coding, so this is probably noob question.
Thanks!
EDIT: I changed it to this.gameObject and now it says the name 'gameObject' does not denote a valid type. When I click on the error it bring me to line 9.
Thanks!
Why is the line in parentheses? It shouldn't be...
I think you're thinking thisLootableItem = this.gameObject;
You need to change the line to:
thisLootableItem = this.gameObject;
EDIT: converting to comment (@Jamora posted right comment first)
Now it says "the name 'gameObject' does not denote a valid type. When I click on the error, it brings me to line 9.
Yes, I don't know why you put () over that statement.
It should be
thisLootableItem = this GameObject;
Not
(thisLootableItem = this GameObject;)
I guess he added () just to help us find the proper line.
Doesn't using 'this' destroy the script and not the gameObject?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
" ';' expected. Insert a semicolon at the end." Error Help 1 Answer
Error in distance coding 1 Answer