Raised This Month: $32 Target: $400
 8% 

Solved Best way of using or statments


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TrullSin
Senior Member
Join Date: Jun 2018
Old 01-04-2019 , 16:31   Best way of using or statments
Reply With Quote #1

What is the best way to use OR statments?
For Example, I want to check first something and if that thing it is ok it wont check for the second and if the first is not ok it will check for the second, something like that. I don't know if it helps but it is for CS:GO

Last edited by TrullSin; 01-05-2019 at 17:02.
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-04-2019 , 17:40   Re: Best way of using or statments
Reply With Quote #2

If you like know something about coding, post in right section.
Quote:
Scripting (17 Viewing)
Scripting in SourcePawn
And https://wiki.alliedmods.net/Category...eMod_Scripting





There is... two kind, how you like to use.

PHP Code:
    bool first_something;
    
bool second_something;

    
second_something true;


    if( 
first_something )
    {
        
// Use this code block only
    
}
    else if( 
second_something )
    {
        
// Use this code block only
    
}

..........

    if( 
first_something || second_something )
    {
        
// if one of variable is true, use this code block
    


Last edited by Bacardi; 01-04-2019 at 17:44.
Bacardi is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 01-04-2019 , 18:38   Re: Best way of using or statments
Reply With Quote #3

Yea my bad, I thought I was posting in the right place, for example I was trying to make something to that prime code (https://forums.alliedmods.net/showpo...29&postcount=3)

PHP Code:
if (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820))
    {
        
KickClient(client"");
        return;
    }
    else if (
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029))
    {
        
KickClient(client"");
        return;
    } 
How could I make the bool and the other stuff with this variables inside if?
TrullSin is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-05-2019 , 02:08   Re: Best way of using or statments
Reply With Quote #4

You not necessary need add variables... ? I'm not sure what you are planning. You could tell more specific.
...
In if() statement you do conditions, check something, is it TRUE or FALSE.
Using

What your code does is compare result to one of enum group values https://github.com/KyleSanderson/Ste...amWorks.inc#L6
It looks like if( 1 == result )
PHP Code:
/* results from UserHasLicenseForApp */
enum EUserHasLicenseForAppResult
{
    
k_EUserHasLicenseResultHasLicense 0,                    // User has a license for specified app
    
k_EUserHasLicenseResultDoesNotHaveLicense 1,            // User does not have a license for the specified app
    
k_EUserHasLicenseResultNoAuth 2,                        // User has not been authenticated
}; 







But if you insist, to use bool variables.
PHP Code:


    bool first 
= (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820));
    
bool second = (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029));

    if(
first || second)
    {
        
KickClient(client"");
        return; 
    } 

Last edited by Bacardi; 01-05-2019 at 02:09.
Bacardi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-05-2019 , 07:48   Re: Best way of using or statments
Reply With Quote #5

Using bool variables is less efficient than just using the results raw because in SourcePawn, || and && are short-circuited operators.

What does that mean? It means that in certain conditions, the second argument is never evaluated.
  • For || the second argument is never evaluated if the first argument is true
  • For && the second argument is never evaluated if the first argument is false

So, why is it more efficient to use the results raw? Because of this:

PHP Code:
if (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820) ||
    
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029))
{
   
// SteamWorks_HasLicenseForApp(client, 54029) is never called if they have a license for app 624820


Edit: If you really want to use a variable, you can still do this:

PHP Code:
bool notLicensed k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820) ||
    
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029); 
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-05-2019 at 07:52.
Powerlord is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 01-05-2019 , 08:26   Re: Best way of using or statments
Reply With Quote #6

What those apps are anyway ? Csgo is one of those, is second TF2?
__________________
Do not Private Message @me
Bacardi is offline
brunoronning
Senior Member
Join Date: Jan 2014
Location: Brazil
Old 01-05-2019 , 08:40   Re: Best way of using or statments
Reply With Quote #7

Quote:
Originally Posted by Bacardi View Post
What those apps are anyway ? Csgo is one of those, is second TF2?
https://steamdb.info/sub/54029/
__________________
brunoronning is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 01-05-2019 , 10:53   Re: Best way of using or statments
Reply With Quote #8

This one is not working

PHP Code:
if (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820) ||
    
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029))
    {
        
KickClient(client"");
        return;
    } 
And when compiling with this, I get a warning 217: loose indentation in the
PHP Code:
return 
after KickClient.

I have the CS:GO for like a few years, and when I enter, I get kicked.

Last edited by TrullSin; 01-05-2019 at 10:56. Reason: Added info
TrullSin is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 01-05-2019 , 11:08   Re: Best way of using or statments
Reply With Quote #9

You should give them a reason for kicking.

PHP Code:

if (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820))
{
    
KickClient(client"reason 1");
    return;
}

if (
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029))
{
    
KickClient(client"reason 2");
    return;

This is how I would write this code.
Also use TAB in code for white spaces to avoid that error.
__________________

Last edited by Ilusion9; 01-05-2019 at 11:08.
Ilusion9 is offline
TrullSin
Senior Member
Join Date: Jun 2018
Old 01-05-2019 , 12:38   Re: Best way of using or statments
Reply With Quote #10

Quote:
Originally Posted by Ilusion9 View Post
You should give them a reason for kicking.

PHP Code:

if (k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client624820))
{
    
KickClient(client"reason 1");
    return;
}

if (
k_EUserHasLicenseResultDoesNotHaveLicense == SteamWorks_HasLicenseForApp(client54029))
{
    
KickClient(client"reason 2");
    return;

This is how I would write this code.
Also use TAB in code for white spaces to avoid that error.
Not working, I get kicked and I have CS:GO for the last 2 years or more, and I got upgraded after the update.. I think that way is checking for the first and then it will check for the second and I dont have the appid 54029 because I didn't buy prime.
TrullSin is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode