SA-MP Forums Archive
Else statement get's called, even though if statement above is true - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Else statement get's called, even though if statement above is true (/showthread.php?tid=635603)



Else statement get's called, even though if statement above is true - Riwerry - 10.06.2017

Hello, I have a little issue in my code. Shortly, inside of callback OnPlayerClickPlayerTextDraw I have this if and else statement:

PHP код:
// ...
else if(playertextid == MDC_g_sPlayer[playerid][E_MDC_TEXTDRAW][39])
{
    if(
MDC_g_sPlayer[playerid][E_MDC_LOOK_UP_CACHE] == MDC_LOOK_UP_CACHE_ESSENTIAL)
    {
    }
    else
    {
        
printf("%i"MDC_g_sPlayer[playerid][E_MDC_LOOK_UP_CACHE]); //Prints 1, so it equals to MDC_LOOK_UP_CACHE_ESSENTIAL
        
MDC_Update(playeridMDC_UPDATE_TECHNIQUE_WIPE_CONTENT_MDC_ITEM_LOOK_UPMDC_CONTENT_LICENSE);
    }
    return 
1;
}
//... 
So, the else statement is being called, even though the if above is true. But once I add some code under if code block, else statement isn't getting called.


Re: Else statement get's called, even though if statement above is true - SyS - 10.06.2017

are you sure about it? print and check MDC_LOOK_UP_CACHE_ESSENTIAL too.


Re: Else statement get's called, even though if statement above is true - Riwerry - 10.06.2017

PHP код:
#define MDC_LOOK_UP_CACHE_ESSENTIAL            (1) 
And when I do this, it's also working fine
PHP код:
else if(playertextid == MDC_g_sPlayer[playerid][E_MDC_TEXTDRAW][39]) 

    
printf("%i"MDC_g_sPlayer[playerid][E_MDC_LOOK_UP_CACHE]); //Prints 1, so it equals to MDC_LOOK_UP_CACHE_ESSENTIAL 
    
if(MDC_g_sPlayer[playerid][E_MDC_LOOK_UP_CACHE] == MDC_LOOK_UP_CACHE_ESSENTIAL
    { 
    } 
    else 
    { 
        
MDC_Update(playeridMDC_UPDATE_TECHNIQUE_WIPE_CONTENT_MDC_ITEM_LOOK_UPMDC_CONTENT_LICENSE); 
    } 
    return 
1

So does this:
PHP код:
else if(playertextid == MDC_g_sPlayer[playerid][E_MDC_TEXTDRAW][39]) 

    
printf("%i"MDC_LOOK_UP_CACHE_ESSENTIAL); //Prints 1 
    
if(MDC_g_sPlayer[playerid][E_MDC_LOOK_UP_CACHE] == MDC_LOOK_UP_CACHE_ESSENTIAL
    { 
    } 
    else 
    { 
        
MDC_Update(playeridMDC_UPDATE_TECHNIQUE_WIPE_CONTENT_MDC_ITEM_LOOK_UPMDC_CONTENT_LICENSE); 
    } 
    return 
1

I have also tried to execute same code in main() and ZCMD command, it worked fine too.
So maybe it has something to do with OnPlayerClickPTD callback?

There must be some magic in my code