- Home /
How do I fix this error in my code
Please help the error says this when I save the code:
This is the code that is used can anyone help me?
The numbers in the parentheses tell you that on line 3, 17 characters from the start of the line, the compiler ran into something that did not make sense. And usually the reported error comes after the actual mistake. You really didn't try very hard to debug your own problem.
@Hawkezley If someone answered your question, please accept their answer. If you don't know how, watch the tutorial video on the right
Post code as code, not as an image. You can't copy and paste an image into a code editor.
Answer by Benproductions1 · Oct 19, 2013 at 10:55 PM
Hello,
You seem to not understand UnityScript syntax in defining variables. It goes like this:
var name:type = value; //with value being optional
In your script on line 3 you do this though:
var TheDamage ; int : 50;
which is just plain wrong syntax. Follow the syntax and you won't get any errors
Another note is that the rest of your program won't compile either and give you a whole ton of other errors:
function update() (
{if (Input.GetButtonDown("Fire1")
{var hit:RaycastHit;
if (Physics.Raycast(/*etc*/));
(Distance = hit.distance;
hit.transform.SendMessage(/*etc*/);)
}
If you write this in a more readable format you get:
function update() ({
if (Input.GetButtonDown("Fire1") {
var hit:RaycastHit;
if (Physics.Raycast(/*etc*/)); {
Distance = hit.distance;
hit.transform.SendMessage(/*etc*/);)
}
I'm sure you can figure out what you did wrong there. Just to make it a little easier, I'll make a check list for you:
-2x random ( or ) that shouldn't be there
-1x missing ( or )
-2x missing { or }
-1x random ; that shouldn't be there
Hope this helps,
Benproductions1
Thank yo very much I'm new to this s this website is amazing and thank you again.
Answer by roflbuddy · Oct 19, 2013 at 10:57 PM
var TheDamage : int = 50;
var Distance : float;
function Update () {
if(Input.GetButtonDown("Fire1")){
var hit : RaycastHit;
if (Physics.Raycast (transform.position, transform.TransofmDirection(Vector3.forward), hit));
Distance = hit.distance;
hit.transform.SendMessage("ApplyDamage", TheDamage, SendMessageOptions.DontRequireReceiver);
}
}
I'd like to note that posting the fixed code will NOT help the OP. This answer does not comply with the FAQ and I will therefore give a -1
Also you should learn to indent ;)
@Benproductions1 - while I agree with your sentiments about education, @roflbuddy did pickup on one bug you missed ;)
The situation of the OP is unknown, so the lack of capitalization of update
might or might not have been deliberate and it is actually called from another script. That's why I left it out ;)
I am sorry guys i understand. But Benproductions1 did point out everything that was wrong, so i just made it easier for the OP. But i wont do it again :)
@roflbuddy: Giving people code makes it easier for them in the short term, but also means they will likely just copy and paste it, meaning they'll be back in an hour with another, very similar question. It might be slightly easier for them in the short term, but not better for them.
Your answer
Follow this Question
Related Questions
Warning: "Can not play a disabled audio source" 1 Answer
What Am I doing wrong? 1 Answer
Animation script error 1 Answer
Console Error 1 Answer
Weird compiler error code 1 Answer