Frictional Games Forum (read-only)

Full Version: Double if(GetEntitiesCollide - Problem [SOLVED]
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello smart people ^^

I have a problem with my if-statement.
The error is: Expected exrpession value.

My script is:


void OnCollide_3(string &in asParent, string &in asChild, int alState)
{
if(GetEntitiesCollide("stone_med01_brown_1", "ScriptArea_2") == true) && if(GetEntitiesCollide("stone_med01_brown_2", "ScriptArea_2") == true) <-- Points to this line
{
FadeOut(0);
PlaySoundAtEntity("", "explosion_rock_large", "Player", 0.5f, false);
}
}

But what is wrong.. I can't seem to figure it out myself..
(07-13-2012, 04:32 PM)beecake Wrote: [ -> ]Hello smart people ^^

I have a problem with my if-statement.
The error is: Expected exrpession value.

My script is:


void OnCollide_3(string &in asParent, string &in asChild, int alState)
{
if(GetEntitiesCollide("stone_med01_brown_1", "ScriptArea_2") == true) && if(GetEntitiesCollide("stone_med01_brown_2", "ScriptArea_2") == true) <-- Points to this line
{
FadeOut(0);
PlaySoundAtEntity("", "explosion_rock_large", "Player", 0.5f, false);
}
}

But what is wrong.. I can't seem to figure it out myself..
I'm no expert in c++ but i think for a multiple condition if statement, you only need one "if" then enclose both conditions wothin the parenthesis seperated by the &&.
You are probably right, but the error is still there
(07-13-2012, 06:55 PM)beecake Wrote: [ -> ]You are probably right, but the error is still there

Omyn is correct. If statements don't return values, so using the logical AND operator on two if statements won't work. You're supposed to place the condition within the if statement's parenthesis. The condition being the statements that can evaluate to either true or false.

PHP Code:
if(GetEntitiesCollide("stone_med01_brown_1""ScriptArea_2") == true
&& GetEntitiesCollide("stone_med01_brown_2""ScriptArea_2") == true
Here's an example of the double if statement that Frictional Games used for the book puzzle in the archives (it's actually 3, but I removed the last one so you can compare it to yours easier). It's all one line, each part is separated by "(space)&&(space)", and the second part doesn't have the extra pair of parentheses ().
if(GetLocalVarInt("VarSecretBook_1") == 1 && GetLocalVarInt("VarSecretBook_2") == 1

Hope that helped.
YYYYES i understand it now! And it also works ^_^ You guys are so brilliant Big Grin