Raised This Month: $51 Target: $400
 12% 

Cannot think about a desc for this (operators)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hectorz0r
Senior Member
Join Date: Oct 2008
Old 08-16-2010 , 11:28   Cannot think about a desc for this (operators)
Reply With Quote #1

I'm trying to find an if inside of another if, yea I know it doesnt make any sense, but if you take a look at the exemple you'll get my point.

PHP Code:
get_pcount()
{
    new 
players

    
for(new 1<= MaxClientsx++)
        if(
IsClientInGame(x))
            
players++

    return 
players

I dont know, but a long time ago I've seen something with the "?" and ":" operators, in a case that looked like this.
I'm not that much experienced with operators, if somebody could tell me a bit more about those two, or atleast give me a link.

Trying to:

PHP Code:
get_pcount(bool:alive)
{
    new 
players

    
for(new 1<= MaxClientsx++)
        if(
/*alive = true, well you know.. include IsPlayerAlive(x) && or !IsPlayerAlive(x) && otherwise.*/ IsClientInGame(x))
            
players++

    return 
players

Note: I know I could do something like the this \/... But it wont help me since I'll need to check the "if inside of another if" more than once.

PHP Code:
get_pcount(bool:alive)
{
    new 
players

    
for(new 1<= MaxClientsx++)
    {
        if(
alive)
        {
            if(
IsPlayerAlive(x) && IsClientInGame(x))
                
players++
        }

        else
            if(!
IsPlayerAlive(x) && IsClientInGame(x))
                
players++
    }

    return 
players

__________________


Last edited by hectorz0r; 08-16-2010 at 11:35.
hectorz0r is offline
DarkEnergy
SourceMod Donor
Join Date: Apr 2008
Location: Georgia Tech, MSECE
Old 08-16-2010 , 11:43   Re: Cannot think about a desc for this (operators)
Reply With Quote #2

http://en.wikipedia.org/wiki/Ternary_operation

condition? statement if true : statement if false ;

nested operations
condition? (condition2? statement if true2 : statement if false2 ) : statement if false ;
__________________
War3:Source Developer
"Your CPU is just a bunch of Muxes"
DarkEnergy is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-16-2010 , 11:47   Re: Cannot think about a desc for this (operators)
Reply With Quote #3

IsPlayerAlive returns a boolean, 'alive' is a boolean... 1+1=?

PHP Code:
get_pcount(bool:alive)
{
    new 
players

    
for(new 1<= MaxClientsx++)
    {
        if(
IsClientInGame(x) && IsPlayerAlive(x) == alive)
        {
            
players++
        }
    }

    return 
players

EDIT: to actually answer your question, in case there was no clean way to do it, you'd have no choice but to repeat the checks. Although you could do the IsClientInGame check before anything else to avoid getting a runtime error from IsPlayerAlive.
__________________
plop

Last edited by p3tsin; 08-16-2010 at 11:56.
p3tsin is offline
hectorz0r
Senior Member
Join Date: Oct 2008
Old 08-16-2010 , 12:00   Re: Cannot think about a desc for this (operators)
Reply With Quote #4

Quote:
Originally Posted by p3tsin View Post
IsPlayerAlive returns a boolean, 'alive' is a boolean... 1+1=?

PHP Code:
get_pcount(bool:alive)
{
    new 
players

    
for(new 1<= MaxClientsx++)
    {
        if(
IsClientInGame(x) && IsPlayerAlive(x) == alive)
        {
            
players++
        }
    }

    return 
players

EDIT: to actually answer your question, in case there was no clean way to do it, you'd have no choice but to repeat the checks. Although you could do the IsClientInGame check before anything else to avoid getting a runtime error from IsPlayerAlive.
Erhm, I through there was a different method, so the ONLY way of doing this is with the following method, right?

PHP Code:
get_pcount(bool:thisbool:thatbool:something)
{
    new 
players

    
for(new 1<= MaxClientsx++)
        if(
IsClientInGame(x))
        {
            if(
this)
            {
                if(
bla1)
                    
players++
            }

            if(
that)
            {
                if(
bla2)
                    
players++
            }

            if(
something)
            {
                if(
bla3)
                    
players++
            }
        }

    return 
players

__________________


Last edited by hectorz0r; 08-16-2010 at 12:03. Reason: typo
hectorz0r is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-16-2010 , 12:12   Re: Cannot think about a desc for this (operators)
Reply With Quote #5

Your example code is a rather confusing without a real case situation. But surely you can combine the conditions, and make them if - else if (otherwise one player could increment the count multiple times)

PHP Code:
get_pcount(bool:thisbool:thatbool:something)
{
    new 
players

    
for(new 1<= MaxClientsx++)
    {
        if(
IsClientInGame(x))
        {
            if(
this && bla1)
            {
                
players++
            }
            else if(
that && bla2)
            {
                
players++
            }
            else if(
something && bla3)
            {
                
players++
            }
        }
    }

    return 
players

Or even this, although it may be a little harder to read

PHP Code:
if(IsClientInGame(x) && ((this && bla1) || (that && bla2) || (something && bla3)))
{
    
players++

__________________
plop
p3tsin is offline
atom0s
Senior Member
Join Date: Jul 2009
Old 08-16-2010 , 13:02   Re: Cannot think about a desc for this (operators)
Reply With Quote #6

Edit :: Nvm for some reason my compiler messed up.. -.-
atom0s is offline
Reply



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 07:10.


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