- Home /
Javascript Syntax Errors
hey, sorry for the bad programming, but I need some help fixing the syntax errors here:
#pragma strict
var map : GameObject;
var onSound : AudioClip;
var offSound : AudioClip;
var canView : Boolean = false;
var viewing : Boolean = false;
function start ()
{
map.GetComponent(MeshRenderer).enabled = false;
canView = false;
viewing = false;
}
function OnTriggerCollider (Col : Collider)
{
if (Col.tag == "Player" && Input.GetKeyDown("e"))
{
canView = true;
audio.PlayOneShot(onSound);
destroy(gameObject);
}
}
function Update ()
{
if (canView = true && Input.GetKeyDown("e"))
{
audio.PlayOneShot(onSound);
map.GetComponet(MeshRenderer).enabled = true;
viewing = true;
}
if (viewing = true && Input.GetKeyDown("e"))
{
audio.PlayOneShot(offSound);
map.GetComponent(MeshRenderer).enabled = false;
viewing = false;
}
}
here are some errors I got when I compiled my script:
Assets/My stuff/My scripts/ViewMap.js(29,21): BCE0044: expecting ), found '='.
Assets/My stuff/My scripts/ViewMap.js(29,52): BCE0043: Unexpected token: ).
Assets/My stuff/My scripts/ViewMap.js(37,21): BCE0044: expecting ), found '='.
Assets/My stuff/My scripts/ViewMap.js(37,52): BCE0043: Unexpected token: ).
sorry for knowing so little about scripting, I'll try to improve :)
sorry for knowing so little about scripting, I'll try to improve :)
It's not where you are that matters here, its where you're going and the way you do it :D
Answer by richyrich · Nov 22, 2014 at 12:59 AM
Change:
if (canView = true && Input.GetKeyDown("e"))
to
if (canView == true && Input.GetKeyDown("e"))
and
if (viewing = true && Input.GetKeyDown("e"))
to
if (viewing == true && Input.GetKeyDown("e"))
Reason: You are currently using assignment operator (=) and you need to be checking for equivalence (==)
Answer by kdubnz · Nov 22, 2014 at 01:08 AM
Looks like you are confusing the assignment operator = and the equality test operator ==
The if statements require an equality test operator.