- Home /
Various Code errors, found X was expecting Y, missing ";", and "can't declair functions on the fly"
My code, as good as i can do, probably not the best but ya'know. anyway, Its giving me grief in the console in Unity, telling me to swap ='s for :'s ect. So can someone have a look see whats up? Thanks!
I get these errors: (17,18) expecting(, found 'OnMouseOver'. (19,9) Unexpected token: if. ( 21,20) expecting :, found '='.
var maxDist : float;
var forceStrength = 10.0;
var reverseStrength = -10.0;
private var applyForce = false;
private var reverseForce = false;
function Awake()
{
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
{
if(hit.transform.tag == "Dynamic")
{
function OnMouseOver();
{
if(Input.GetMouseButton(0));
{
applyForce = true
}
else
{
applyForce = false;
}
if(Input.GetMouseButton(0))
{
reverseForce = true;
}
else
{
reverseForce = false;
}
}
}
function OnMouseExit()
{
applyForce = false;
reverseForce = false;
}
}
}
Thanks.
Could you edit your question title and make it something that might be useful to a future searcher? Unity Answers is a $$anonymous$$nowledge Base and as such it should have questions that are meaningful.
Answer by Bunny83 · Jul 09, 2012 at 12:59 PM
You can't declare functions on the fly. This is not a dynamic scripting language, it's a compiled language. UnityScript works way different to the JavaScript you might know from website developing.
I guess you want something like that:
var maxDist : float;
var forceStrength = 10.0;
var reverseStrength = -10.0;
private var applyForce = false;
private var reverseForce = false;
function OnMouseOver()
{
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.forward, hit, maxDist))
{
if(hit.transform.tag == "Dynamic")
{
applyForce = Input.GetMouseButton(0);
reverseForce = Input.GetMouseButton(0);
}
}
}
function OnMouseExit()
{
applyForce = false;
reverseForce = false;
}
Answer by delstrega · Jul 08, 2012 at 07:14 AM
From what I can tell, you are defining the OnMouseOver() function inside of Awake() which of course doesn't work. Additionally there's a semicolon at the end of this line:
function OnMouseOver();
And from the looks of your code it seems to me, that the parentheses got wrong.
All those things confuse the compiler and lead to stupid error messages like the one you mentioned. So try to go through your code again and fix parentheses, semicolons and the order of stuff and you should be fine.
Thanks, I can be too messy for my own good lol, the problem now is that I need to define On$$anonymous$$ouseOver within Awake so that the "dynamic" shapes will register the mouse hover on them, I don't know how else you'd do it D:
I've converted your answer to a comment, Answer on UA means Solution and not Reply - there's an Add New Comment button hidden on the right of the screen.
There's still a ';' at the end of if(Input.Get$$anonymous$$ouseButton(0));
Hope you got it working. Dont forget to spread some karma and maintain structure on the site by selecting best answer
$$anonymous$$aybe that's because Awake() is only called once at the beginning, try moving that piece of code into On$$anonymous$$ouseOver().
Your answer
Follow this Question
Related Questions
BCE0044: expecting :, found 'if' ??? 1 Answer
Expecting :, found ; and can't figure it out... 2 Answers
Error Java script 1 Answer
BCE0044: expecting '"', found '\r'. 1 Answer