PDA

View Full Version : Else statement get's called, even though if statement above is true


Riwerry
10/06/2017, 12:14 PM
Hello, I have a little issue in my code. Shortly, inside of callback OnPlayerClickPlayerTextDraw I have this if and else statement:

// ...
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(playerid, MDC_UPDATE_TECHNIQUE_WIPE_CONTENT, _, MDC_ITEM_LOOK_UP, MDC_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. ???

SyS
10/06/2017, 12:20 PM
are you sure about it? print and check MDC_LOOK_UP_CACHE_ESSENTIAL too.

Riwerry
10/06/2017, 12:23 PM
#define MDC_LOOK_UP_CACHE_ESSENTIAL (1)

And when I do this, it's also working fine :D
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(playerid, MDC_UPDATE_TECHNIQUE_WIPE_CONTENT, _, MDC_ITEM_LOOK_UP, MDC_CONTENT_LICENSE);
}
return 1;
}

So does this:
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(playerid, MDC_UPDATE_TECHNIQUE_WIPE_CONTENT, _, MDC_ITEM_LOOK_UP, MDC_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 :D