- Home /
C# Question Regarding If Statement Errors, Booleans
Hey all, I'm trying to figure out if this is a C# error or I have the logic wrong or what. The following snippet of code is returning several errors. Does this look problematic or is there a parsing error I'm too tired to see?
void WindowFunction (int windowID) {
if(objecttwo != null) && (objectone != null) {
GUILayout.Label (characterSpeech1);
Debug.Log("Message 1");
}
else if(objecttwo == null) && (objectone == null) {
GUILayout.Label (characterSpeech2);
Debug.Log("Message 2");
}
else if(objecttwo != null) && (objectone == null) {
GUILayout.Label (characterSpeech3);
Debug.Log("Message 3");
}
else(objecttwo == null) && (objectone != null) {
GUILayout.Label (characterSpeech4);
Debug.Log("Message 4");
}
}
Returns:
error CS1525: Unexpected symbol &&' error CS1519: Unexpected symbol
else' in class, struct, or interface member declaration
error CS1519: Unexpected symbol ==' in class, struct, or interface member declaration error CS1519: Unexpected symbol
==' in class, struct, or interface member declaration
error CS1519: Unexpected symbol (' in class, struct, or interface member declaration error CS1519: Unexpected symbol
)' in class, struct, or interface member declaration
error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration
Answer by robertbu · May 02, 2014 at 03:53 AM
The whole 'if' statements must be enclosed in '()'. For example line 3 should be:
if ((objecttwo != null) && (objectone != null)) {
This is the correct answer. See this page for more reference.
I can't upvote it until I have at least 15 reputation but this is absolutely the right answer and everything works now.
Thank you so much.
Your answer
Follow this Question
Related Questions
Scavenger Hunt List Bools Question 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Value not changing back to where its supposed to... 0 Answers
Use a #if statement to check if a script exists in project? 0 Answers