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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help [Solved] Two Conditionals on same line?
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#1
[Solved] Two Conditionals on same line?

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: (Select All)
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: (Select All)
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!

Discord: Romulator#0001
[Image: 3f6f01a904.png]
(This post was last modified: 06-11-2015, 10:10 AM by Romulator.)
06-10-2015, 03:23 PM
Find
Kreekakon Offline
Pick a god and pray!

Posts: 3,063
Threads: 70
Joined: Mar 2012
Reputation: 124
#2
RE: Two Conditionals on same line?

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.

[Image: Tv0YgQb.gif]
Image by BandyGrass
06-10-2015, 03:53 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: Two Conditionals on same line?

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: (Select All)
if(GetLocalVarInt("can_craft") == && GetLocalVarInt("cant_craft") == -1

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

PHP Code: (Select All)
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.

(This post was last modified: 06-10-2015, 04:12 PM by Mudbill.)
06-10-2015, 04:07 PM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#4
RE: Two Conditionals on same line?

(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.

Trying is the first step to success.
06-10-2015, 09:26 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: Two Conditionals on same line?

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.

06-10-2015, 10:01 PM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#6
RE: Two Conditionals on same line?

(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*

Discord: Romulator#0001
[Image: 3f6f01a904.png]
06-11-2015, 10:09 AM
Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#7
RE: [Solved] Two Conditionals on same line?

(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.

Trying is the first step to success.
06-11-2015, 10:21 AM
Find
TheGreatCthulhu Offline
Member

Posts: 213
Threads: 10
Joined: Oct 2010
Reputation: 32
#8
RE: [Solved] Two Conditionals on same line?

(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.
06-15-2015, 11:47 AM
Find
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#9
RE: [Solved] Two Conditionals on same line?

(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.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
06-15-2015, 12:04 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#10
RE: [Solved] Two Conditionals on same line?

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.

06-15-2015, 02:16 PM
Find




Users browsing this thread: 1 Guest(s)