- Home /
Engine Only Returns Responses for False
var dead:boolean=false;
function Update (){
if(Health.health==0){
dead=true;
}
}
if(dead==true){
print("You are dead"); //never works
}
if(dead==false){
print("You are not dead"); //consistently works
}
The game will return the "You are not dead" message when the variable is false, but will not return "You are dead" when the variable is true. Why is the script only working for the value false? If I reverse the two and for example make a variable "alive" that is true when health is not 0, it still does not return anything upon death. Any help? I can elaborate if there's any necessary information I've left out.
Answer by Kryptos · Apr 04, 2012 at 06:57 AM
I'm surprised that this code even compiled. Every code statement has to be inside a function (or method in C#).
As for your problem, the condition tests should be inside the Update function so that they may be evaluated at each frame:
var dead:boolean=false;
function Update (){
if(Health.health==0){
dead=true;
}
if(dead==true){
print("You are dead");
}
if(dead==false){
print("You are not dead");
}
}
But this will print a message each frame. So you may need to add some logic to prevent that.
Answer by BluexStudios · Apr 04, 2012 at 10:04 AM
try putting the two if statements under the funtion Update()
Your answer
Follow this Question
Related Questions
Boolean problem!! 2 Answers
Boolean while looking at a game object? 1 Answer
The public bool will not change unless i set it 1 Answer
Why won't my if result to true? 1 Answer
Boolean Uncheck Inspector if False 2 Answers