Frictional Games Forum (read-only)
[SCRIPT] [Solved] Two Conditionals on same line? - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] [Solved] Two Conditionals on same line? (/thread-30113.html)



[Solved] Two Conditionals on same line? - Romulator - 06-10-2015

Was just wondering if I can make two if statements on the same line and progress with the code if both conditions are met?

PHP Code:
void OnStart()
    {
    
SetLocalVarInt("can_craft"0);
    
AddEntityCollideCallback("Player""craft_box""check_collide"false0);
    
SetEntityPlayerLookAtCallback("sign_key_1""key_1_message"false);  //Signs are ScriptAreas.
    
}

void key_1_message(string &in asEntityint alState)
    {
        if(
GetLocalVarInt("can_craft") == 1//Put extra conditional here
        
{
        
SetMessage("CraftTable""Key_1"0);
        }
    } 

Spoiler below!
And this is what changes "can_craft", not that it really matters.
PHP Code:
void check_collide(string &in asParentstring &in asChildint alState)
    {
    if(
alState == 1)
        {
        if(
GetLocalVarInt("can_craft") < 1)
            {
            
AddLocalVarInt("can_craft"1);
            }
        }
    else
        {
        if(
GetLocalVarInt("can_craft") > 0)
            {
            
AddLocalVarInt("can_craft", -1);
            }
        }
    } 


The other conditional I need to check is if the Player is actually looking at the ScriptArea (in this case; sign_key_1), since if they are not, on looking away, the message just reappears for a bit.

I can code an extra line or two to actually make it work, but I would like to see if its possible to do it on one line, since it probably makes my code just that little bit more efficient and would benefit me somewhat in the future.

Thanks!


RE: Two Conditionals on same line? - Kreekakon - 06-10-2015

Multiple IF conditions can be added with &&. Similarly, || would mean that the IF would run if ONE of the conditions was met.

Like say:

if(int1==2 && int2==5)

This IF would run if both int1 equaled 2 and int2 equaled 5.

And then:

if(int1==2 || int2==5)

This IF would run if any one of those two were true.


RE: Two Conditionals on same line? - Mudbill - 06-10-2015

In some languages, you can write the keyword and as a substitute for &&. Similarly, you can use or for ||.

*You can't do this in AngelScript, but it explains their purpose.

PHP Code:
if(GetLocalVarInt("can_craft") == && GetLocalVarInt("cant_craft") == -1

You can also do this, which has a slight difference:

PHP Code:
if(GetLocalVarInt("can_craft") == 1) if(GetLocalVarInt("cant_craft") == -1

This would only ask the second if-statement if the first one passes. The top one will ask both in the same operation.


RE: Two Conditionals on same line? - FlawlessHappiness - 06-10-2015

(06-10-2015, 04:07 PM)Mudbill Wrote: *You can't do this in AngelScript, but it explains their purpose.

I'm pretty sure you can.
Writing "or" in my editor changes the color of it.
I'm also fairly certain i've used it before.


RE: Two Conditionals on same line? - Mudbill - 06-10-2015

What editor do you use though? For example Notepad++ will highlight whatever it feels like depending on the markup language. It has no relation to actual in-game scripts.

The only markup I truly trust is Eclipse's, because it's entirely focused on Java and does it better than most other things I know of.


RE: Two Conditionals on same line? - Romulator - 06-11-2015

(06-10-2015, 03:53 PM)Kreekakon Wrote: Multiple IF conditions can be added with &&. Similarly, || would mean that the IF would run if ONE of the conditions was met.

Like say:

if(int1==2 && int2==5)

This IF would run if both int1 equaled 2 and int2 equaled 5.

And then:

if(int1==2 || int2==5)

This IF would run if any one of those two were true.

I knew I had seen this before somewhere on the wiki. But I couldn't find it. Thanks for the help Kreek. *throws you a reputation*


RE: [Solved] Two Conditionals on same line? - FlawlessHappiness - 06-11-2015

(06-10-2015, 10:01 PM)Mudbill Wrote: What editor do you use though? For example Notepad++ will highlight whatever it feels like depending on the markup language. It has no relation to actual in-game scripts.

The only markup I truly trust is Eclipse's, because it's entirely focused on Java and does it better than most other things I know of.

I use Geany.
With this setup.


RE: [Solved] Two Conditionals on same line? - TheGreatCthulhu - 06-15-2015

(06-11-2015, 10:09 AM)(拉赫兰) Romulator Wrote: I knew I had seen this before somewhere on the wiki. But I couldn't find it. Thanks for the help Kreek. *throws you a reputation*

Maybe here? Hm... I only now noticed I didn't put anything about logical operators in the "At a Glance" section.


RE: [Solved] Two Conditionals on same line? - Romulator - 06-15-2015

(06-15-2015, 11:47 AM)TheGreatCthulhu Wrote:
(06-11-2015, 10:09 AM)(拉赫兰) Romulator Wrote: I knew I had seen this before somewhere on the wiki. But I couldn't find it. Thanks for the help Kreek. *throws you a reputation*

Maybe here? Hm... I only now noticed I didn't put anything about logical operators in the "At a Glance" section.

A-ha! Big Grin Knew it! Cheers Cthulhu
Senpai noticed me.


RE: [Solved] Two Conditionals on same line? - Mudbill - 06-15-2015

I guess that page does show you can use the text word instead of the symbols. My bad. "and" and "or" are fine to use, I just personally never do xP

The life of a techie.