- Home /
Converted a script from C# to JS, Unexpected Token: .. What did I do?
So, I have this script that I had, but then began modifying. Since it was in C# (it was originally not mine, I just used it to start off(I'm mostly new to Unity, and development in general, although I have worked much with 2D before and have very quickly familiarized scripting syntax)), I had a bit of trouble adding my own spread modifier. I chose to convert it to UnityScript, so that I would be able to more quickly do things with it. I haven't been able to test it, but I can work all translating kinks out after I fix this. I'm on the very end:
function ShowHits(RaycastHit.hit)
{
switch (hit.transform.tag)
{
case "bullet":
// do nothing if 2 bullets collide
break;
case "Player":
// add blood effect
break;
case "wood":
// add wood impact effects
break;
case "stone":
// add stone impact effect
break;
case "ground":
// add dirt or ground impact effect
break;
default: // default impact effect and bullet hole
Instantiate(impactEffect, hit.point + 0.1f * hit.normal, Quaternion.FromToRotation(Vector3.up, hit.normal));
newBulletHole = Instantiate(bulletHole, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
newBulletHole.transform.parent = hit.transform;
break;
}
}
But when it compiles in Unity, the only error is this: Assets/My Assets/Scripts/Gun.js(509,34): BCE0043: Unexpected token: ..
Line 509 being "function ShowHits(RaycastHit.hit)", the problem is the period between RaycastHit and hit, but there shouldn't be. There were no problems with other instances of RaycastHit.hit and RaycastHit.hits in the script, so, considering this just bewildered me, does anyone know what's going on here? (I have looked and looked around, not finding an answer, so don't flame me if I'm blind)
Answer by Eric5h5 · Apr 24, 2011 at 04:44 AM
You need to define the type of variables used in functions.
function ShowHits (hit : RaycastHit)
That creates a whole slew of errors from the entire script. I'll look through them, but it seems that alot of things relied on that line being structured how it was o_O
"The name 'string' does not denote a valid type ('not found'). Did you mean 'Boo.Lang.Compiler.IO.StringInput'?" is the error for 4 of them, with different names. They are all "does not denote a valid type"
The line had incorrect syntax, so nothing relied on it; you're just seeing the other errors that were already there. There's no 'string' in JS, it's 'String', but that's not related to the error in question.
Ah, thank you for clearing that up. Sometimes I just get effed with capitols and finite syntax like that. I guess I'm just a sucky translator.
Your answer
Follow this Question
Related Questions
Unexpected token: .. 1 Answer
Unexpected Token: Collider. 1 Answer
Unexpected Token }. 1 Answer
what is an unexpected token 1 Answer
unexpected token 2 Answers