PDA

View Full Version : Q_strncasecmp confusion


John6000
06-16-2007, 02:45 PM
My if statement keeps going into the first bit which means for some reason Q_strncasecmp( HL2MPRules()->MapName() , "tr_", 3) is always true even when I change to a map which does not have that prefix. Anyone have any ideas? thanks:D


if ( Q_strncasecmp( HL2MPRules()->MapName() , "tr_", 3) )
{
m_pWarmupLabel->SetText( "Training Course" );

}
else if ( Q_strncasecmp( HL2MPRules()->MapName() , "sp_", 3) )
{
m_pWarmupLabel->SetText( "Single Player" );
}
else if ( Q_strncasecmp( HL2MPRules()->MapName() , "vs_", 3) )
{
m_pWarmupLabel->SetText( "Humans Vs NPCS" );
}
else
{
m_pWarmupLabel->SetText( string1 );

}

Mike Durand
06-18-2007, 09:36 AM
This function returns when the strings are the same, so your code should look like this:

if ( 0 == Q_strncasecmp( HL2MPRules()->MapName() , "tr_", 3) )
{
m_pWarmupLabel->SetText( "Training Course" );
}
else if ( 0 == Q_strncasecmp( HL2MPRules()->MapName() , "sp_", 3) )
{
m_pWarmupLabel->SetText( "Single Player" );
}
else if ( 0 == Q_strncasecmp( HL2MPRules()->MapName() , "vs_", 3) )
{
m_pWarmupLabel->SetText( "Humans Vs NPCS" );
}
else
{
m_pWarmupLabel->SetText( string1 );
}

lodle
06-18-2007, 06:06 PM
or quickhand

if ( !Q_strncasecmp( HL2MPRules()->MapName() , "tr_", 3) )
{
m_pWarmupLabel->SetText( "Training Course" );
}
else if ( !Q_strncasecmp( HL2MPRules()->MapName() , "sp_", 3) )
{
m_pWarmupLabel->SetText( "Single Player" );
}
else if ( !Q_strncasecmp( HL2MPRules()->MapName() , "vs_", 3) )
{
m_pWarmupLabel->SetText( "Humans Vs NPCS" );
}
else
{
m_pWarmupLabel->SetText( string1 );
}