Confusing error message

OK, Ive been trying to get to grips with the whole accessing variables from another script on another object. (don’t even get me started, 21+ hours now and I still don’t get it…lol)

Anyway… my latest issue is that I am getting this error message -

Assets/Scripts/SlideDoor.js(7,37): UCE0001: ‘;’ expected. Insert a semicolon at the end.

However the line of code it refers to is -

var gotKey : GameObject.GetComponent(PlayerInventory).hasKey;

As you can see it already has a semicolon at the end. So why am I getting this error and why is it telling me to put a semicolon at position 37 (this would not be at the end?)

Help plz guys

You should do

var gotKey : boolean = GameObject.Find(“name”).GetComponent(PlayerInventory).hasKey;

, where [name] is the object having the PlayerInventory script assigned to it.

That is: var [variable_name] : [variable_type] = [variable_assignment];

(obviously, you wasn’t following this synthax, with your line of code). And, regarding the error about the missing semicolon: you are right, the semicolon was already here, but the console cannot show you always the exact error. In poor words, it has a predefined set of messages, and it shows the most suitable one for the actual situation. That’s the reason for the “missing semicolon” message.