Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Putting two "if"s together
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#1
Putting two "if"s together

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.
(This post was last modified: 07-05-2012, 09:35 PM by ApeCake.)
07-05-2012, 09:35 PM
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#2
RE: Putting two "if"s together

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.

(This post was last modified: 07-05-2012, 09:39 PM by Obliviator27.)
07-05-2012, 09:38 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#3
RE: Putting two "if"s together

You were not far off at all:
void mansion_1(string &in entity)
{
if(GetSwingDoorLocked("mansion_1") && GetPropHealth("mansion_1") < 70)
{
SetMessage("Messages", "labdoorlocked", 0);
}
}
(This post was last modified: 07-05-2012, 09:39 PM by Apjjm.)
07-05-2012, 09:38 PM
Find
SilentStriker Offline
Posting Freak

Posts: 950
Threads: 26
Joined: Jul 2011
Reputation: 43
#4
RE: Putting two

Nevermind
(This post was last modified: 07-05-2012, 09:39 PM by SilentStriker.)
07-05-2012, 09:39 PM
Find
himynamebob1 Offline
Member

Posts: 57
Threads: 12
Joined: Jun 2012
Reputation: 0
#5
RE: Putting two "if"s together

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
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
RE: Putting two "if"s together

(07-05-2012, 09:40 PM)himynamebob1 Wrote: Would this work?

No.

Tutorials: From Noob to Pro
07-05-2012, 10:13 PM
Website Find
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#7
RE: Putting two "if"s together

Thanks guys! I'll try it tomorrow. Thanks for the help! Reps for all!
(This post was last modified: 07-05-2012, 10:46 PM by ApeCake.)
07-05-2012, 10:46 PM
Find
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#8
RE: Putting two "if"s together

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.
07-09-2012, 02:00 PM
Find
Cruzore Offline
Senior Member

Posts: 301
Threads: 2
Joined: Jun 2012
Reputation: 37
#9
RE: Putting two "if"s together

try this instead:
if (alState == -1 && GetSwingDoorClosed("leftelevatordoor") == true)

Think, before you speak Google, before you post
07-09-2012, 03:19 PM
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#10
RE: Putting two "if"s together

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"
(This post was last modified: 07-09-2012, 04:49 PM by Apjjm.)
07-09-2012, 04:46 PM
Find




Users browsing this thread: 3 Guest(s)