- Home /
Whats wrong with this code? "expecting :, found '=' " error.
OK, this error has been bugging me for some time now, and I just can't figure it out. Please someone point out the error to me, because as far as I know, my code is correct. I added an extra if statement to check for an objects tag, and suddenly, the code which worked before throws up an error message - not even the new code itself!
The code previously parented a raycast hit object to the controlled object and allowed you to move it around. I am trying to check for tags to see if an object is moveable, or if it is a switch.
Heres the code. I've put in a note where the error occurs, and another note where the newly entered code in. All help is appreciated!
var hasObject: boolean = false; var otherThing: Transform;
function Update () {
var fwd = Camera.main.transform.forward;
var hit : RaycastHit;
var LayerMask = (1<<9) | (1<<10);
Debug.DrawRay(camera.main.transform.position, (transform.position-camera.main.transform.position) * 50, Color.red);
If (Input.GetButtonDown ("Fire2"))
{
if (!hasObject)
{
if (Physics.Raycast(camera.main.transform.position, (transform.position-camera.main.transform.position), hit, 75, LayerMask))
{
otherThing = hit.transform;
//The next line is the new line of code which is causing the error. if (otherThing.tag("Moveable")); { //The line below is where the error is being thrown up. otherThing.rigidbody.isKinematic = true; otherThing.rigidbody.detectCollisions = false; otherThing.transform.position.z = 0; otherThing.parent = transform; otherThing.Find("Glowblock").light.enabled = true; hasObject = true; //This next section is also new. }else if { (otherThing.tag("switchable")); Debug.Log ("This is a switch"); } } }else { otherThing.rigidbody.isKinematic = false; otherThing.rigidbody.detectCollisions = true; transform.DetachChildren(); otherThing.transform.position.z = 0; otherThing.Find("Glowblock").light.enabled = false; hasObject = false; } }
}
Answer by Eric5h5 · Mar 28, 2011 at 05:57 PM
You have a ";" after the if statement.
D'oh! Thanks, that cleared up that error. Trust it to be something so obvious. Now I just need to figure out what format the if statements need to be in, because they aren't working either >_<.
"It is not possible to invoke an expression of type 'String'."
@Alienjesus: Take a look at your syntax for the if statement, you have the keyword capitalized. That might be part of your problem (I posted below citing this as a potential compilation issue)
@Alienjesus: You probably mean to use CompareTag; if otherThing.tag("$$anonymous$$oveable")
isn't correct syntax. You could see if tag == "$$anonymous$$oveable"
, but CompareTag is better.
Answer by swquinn · Mar 28, 2011 at 06:24 PM
As Eric5h5 says above, you have a semi-colon that is causing havoc with your conditional statement (if-block). I did also notice that you have a capitalized "if" statement immediately after your Debug output:
Debug.DrawRay(camera.main.transform.position, (transform.position-camera.main.transform.position) * 50, Color.red);
If (Input.GetButtonDown ("Fire2")) { ... }
should be (note the lower case "if")...
Debug.DrawRay(camera.main.transform.position, (transform.position-camera.main.transform.position) * 50, Color.red);
if (Input.GetButtonDown ("Fire2")) { ... }
Which may also cause you compilation problems for you, I know C# expects the if syntax to be lower case, and I believe JavaScript does as well. Not sure about Boo off hand though.
I'm not sure if it was just a typo when posting your code, or if the keyword is capitalized in your actual code as well. Just thought I'd give you a heads up.
Thanks for the heads up, although that one was actually a typo when i posted it here. I appreciate it though!
Your answer
Follow this Question
Related Questions
Newb question 2 Answers
BCE0044 error 0 Answers
I need help with an error 1 Answer
error help 2 Answers