ApeCake
Member
Posts: 116
Threads: 20
Joined: Jun 2012
Reputation:
4
|
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 |
|
Obliviator27
Posting Freak
Posts: 792
Threads: 10
Joined: Jul 2011
Reputation:
66
|
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 |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
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 |
|
SilentStriker
Posting Freak
Posts: 950
Threads: 26
Joined: Jul 2011
Reputation:
43
|
RE: Putting two
Nevermind
(This post was last modified: 07-05-2012, 09:39 PM by SilentStriker.)
|
|
07-05-2012, 09:39 PM |
|
himynamebob1
Member
Posts: 57
Threads: 12
Joined: Jun 2012
Reputation:
0
|
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 |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Putting two "if"s together
(07-05-2012, 09:40 PM)himynamebob1 Wrote: Would this work?
No.
|
|
07-05-2012, 10:13 PM |
|
ApeCake
Member
Posts: 116
Threads: 20
Joined: Jun 2012
Reputation:
4
|
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 |
|
ApeCake
Member
Posts: 116
Threads: 20
Joined: Jun 2012
Reputation:
4
|
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 |
|
Cruzore
Senior Member
Posts: 301
Threads: 2
Joined: Jun 2012
Reputation:
37
|
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 |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
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 |
|
|