- Home /
How to use if statement with var?
Hi, I'm recieving this error when I attempt to use an if statement with a variable. BCE0044: expecting (, found 'var'.
I'm getting this problem with this code. if var Activate = true;
Can anyone help me please?
Answer by unluckyBastard · Sep 01, 2011 at 12:15 PM
you can't declare a new variable when using an if statement
var activated : boolean = false;
function Update(){
if(activated){
...
}
}
Answer by by0log1c · Sep 01, 2011 at 01:28 PM
Several small mistakes here. As unluckyBastard pointed out, you cannot declare a variable inside a condition, it makes sense, if you think about it...
Also, you're using a single equal symbol '=' which will assign a value rather than compare. You mean to use '=='.
Lastly, the statement to evaluate in a condition must be in-between parenthesis. Hence your code could look like this:
var Activate = true;
if(Activate==true){
//do something
}
OR(cleaner)
var activate:boolean = true;
if(activate){
//do something
}
Your answer
Follow this Question
Related Questions
Error BCE0044 plz help 0 Answers
function in a function error 1 Answer
Error: expecting ( 1 Answer
Assets/Standard Assets/Scripts/General Scripts/follow.js(9,59): BCE0044:unexpected char: 0xAD 1 Answer
Errors in Scripting 4 Answers