Frictional Games Forum (read-only)

Full Version: Putting two "if"s together
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I do not really need this for my custom story, but I am just incredibly curious about this. The question is; how do you make something happen when two (or three, or four, whatever) things are set "true". Example; I want a message to display when my door is locked and when my doors health is lower than 70.
This is what I wrote, mostly looking at another cs, but then failing horribly. I'm think the concept looks like this though, the only part that this is completely wrong.


void mansion_1(string &in entity)
{
if(GetSwingDoorLocked("mansion_1" && GetPropHealth("mansion_1") == i<70))
{
SetMessage("Messages", "labdoorlocked", 0);
}
}

(mansion_1 is the name of the PlayerInteractCallback of the door, and the actual name of the door.)
This above was just me kinda messing around and trying to figure it out. I couldn't get it complete though. And as far as I'm aware there isn't a solution on the wiki. Any help would be appreciated.
Basically, you'd want

if(GetSwingDoorLocked("mansion_1") == false && GetPropHealth("mansion_1") < 70)

I do believe.

Edit: Apjjm responded at the same time. Bah. Anyhow, they're the same script, his is just neater.
You were not far off at all:
Code:
void mansion_1(string &in entity)
{
if(GetSwingDoorLocked("mansion_1") && GetPropHealth("mansion_1") < 70)
{
SetMessage("Messages", "labdoorlocked", 0);
}
}
Nevermind
Would this work?

void mansion_1(string &in entity)

{

if(GetSwingDoorLocked("mansion_1") == 1(orwhatevertrueis)
{
if(GetPropHealth("mansion_1") == i<70)
{
SetMessage("Messages", "labdoorlocked", 0);
}
}
}
(07-05-2012, 09:40 PM)himynamebob1 Wrote: [ -> ]Would this work?

No.
Thanks guys! I'll try it tomorrow. Thanks for the help! Reps for all!
Okay, I hate to bump this thread, but I want something to activate when I pulled a lever and when the door is closed (it's an elevator, you see.) How would I work this out? Something like this?


void elevatorgo(string &in asEntity, int alState)
{
if ((alState == -1) && GetSwingDoorClosed("leftelevatordoor") == true)
{
AddTimer("EG1", 1.5, "elevatorgoes");
PlaySoundAtEntity("", "quest_completed.snt", "Player", 0, false);
PlayGuiSound("move_gate.snt", 2);
}
}

The door is called "leftelevatordoor". It worked without the GetSwingDoorClosed, so the problem is definitely in that part. Thanks in advance.
try this instead:
if (alState == -1 && GetSwingDoorClosed("leftelevatordoor") == true)
Tip for dealing with boolean expressions:
It's worth noting that putting "==true" is redundant - because "x==true" will just evaluate to either "true" or "false" anyway. This is like stating "if saying the door is open is true", when you would normally say "if the door is open".


Likewise for using "==false", you can just use the logical not opeator "!" - e.g. "!x" is the same as "x==false".


Doing this stops a redudant equality check (which hopefully the interpreter optimises out - but it might not), and also makes the code easier to read - it's much easier to read: "if the door is not open" vs "saying the door is open is false"
Pages: 1 2