SA-MP Forums Archive
redundant test ? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: redundant test ? (/showthread.php?tid=66929)



redundant test ? - the_driver - 25.02.2009

Hey guys, i have this piece of script:
Код:
public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerInterior(playerid,14);
	SetPlayerPos(playerid,258.4893,-41.4008,1002.0234);
	SetPlayerFacingAngle(playerid, 270.0);
	SetPlayerCameraPos(playerid,256.0815,-43.0475,1004.0234);
	SetPlayerCameraLookAt(playerid,258.4893,-41.4008,1002.0234);

	// Leaders

	if (classid == 0)
	{
  	GameTextForPlayer(playerid, "Police Chef", 1000, 6);
	}
 	else if (classid == 1)
 	{
  		GameTextForPlayer(playerid, "Federal Agents - Leader", 1000, 6);
	}
 	else if (classid == 2)
 	{
  		GameTextForPlayer(playerid, "La Costra Nostra - Leader", 1000, 6);
	}
 	else if (classid == 3)
 	{
  		GameTextForPlayer(playerid, "Hitman - Leader", 1000, 6);
	}
 	else if (classid == 4)
 	{
  		GameTextForPlayer(playerid, "Da Nang Boys - Leader", 1000, 6);
	}


	// Faction Members
	
	// Police
	
	else if (classid == 5, 6, 7, 8)
	{
	  GameTextForPlayer(playerid, "Police", 1000, 4);
	}
	
	// Federal Agents
	
	else if (classid == 9, 10, 11, 12)
	{
	  GameTextForPlayer(playerid, "Federal Agents", 1000, 4);
	}
	
	// La Costra Nostra
	
	else if (classid == 13, 14, 15, 16)
	{
	  GameTextForPlayer(playerid, "La Costra Nostra Family", 1000, 4);
	}

	
	// Hitman
	
	else if (classid == 17, 18, 19, 20)
	{
	  GameTextForPlayer(playerid, "Hitman", 1000, 4);
	}
	
	// Da Nang Boys
	
	else if (classid == 21, 22, 23)
	{
	  GameTextForPlayer(playerid, "Da Nang Boys", 1000, 4);
	}
	return 1;
}
Now i get this error:
Код:
RPGClasses.pwn(351) : warning 206: redundant test: constant expression is non-zero
RPGClasses.pwn(358) : warning 206: redundant test: constant expression is non-zero
RPGClasses.pwn(365) : warning 206: redundant test: constant expression is non-zero
RPGClasses.pwn(373) : warning 206: redundant test: constant expression is non-zero
RPGClasses.pwn(380) : warning 206: redundant test: constant expression is non-zero
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Warnings.
Now the error lines are:
Код:
351 -> 	else if (classid == 5, 6, 7, 8)
358 ->	else if (classid == 9, 10, 11, 12)
365 ->	else if (classid == 13, 14, 15, 16)
373 -> 	else if (classid == 17, 18, 19, 20)
380 ->	else if (classid == 21, 22, 23)
So i allways make the same mistake... can someone help me ?

-Wickedd


Re: redundant test ? - yom - 25.02.2009

Use switch statement.


Re: redundant test ? - Rks25 - 25.02.2009

pawn Код:
if (classid == 5, 6, 7, 8)
//should be
if (classid == 5 || classid 6 || classid 7|| classid 8)
or easier: an switch()


Re: redundant test ? - the_driver - 25.02.2009

Rks, if i use
Код:
else if (classid == 5 || classid 6 || classid 7|| classid 8)
i get even more errors lol
Код:
RPGClasses.pwn(351) : error 001: expected token: ")", but found "-integer value-"
RPGClasses.pwn(351) : warning 215: expression has no effect
RPGClasses.pwn(351) : error 001: expected token: ";", but found "-integer value-"
RPGClasses.pwn(351) : warning 215: expression has no effect
RPGClasses.pwn(351) : error 001: expected token: ";", but found "-integer value-"
RPGClasses.pwn(351) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


4 Errors.
And how does a switch works.. ? ( i am newbie .. )


Re: redundant test ? - Nero_3D - 25.02.2009

rks just forgot some = (dunno how to call them :S)

and a switch is easy
pawn Код:
switch(classid) //the value we want switch (much if statments just in a better looking way)
{
    //this is the same as if(classid == 0)
    case 0:     GameTextForPlayer(playerid, "Police Chef", 1000, 6);
    case 1:     GameTextForPlayer(playerid, "Federal Agents - Leader", 1000, 6);
    case 2:     GameTextForPlayer(playerid, "La Costra Nostra - Leader", 1000, 6);
    case 3:     GameTextForPlayer(playerid, "Hitman - Leader", 1000, 6);
    case 4:     GameTextForPlayer(playerid, "Da Nang Boys - Leader", 1000, 6);
    //the two points stand for 5-8 (5, 6, 7, 8) here you can write 5, 6, 7, 8 too but .. is easier
    case 5..8:  GameTextForPlayer(playerid, "Police", 1000, 4);
    case 9..12: GameTextForPlayer(playerid, "Federal Agents", 1000, 4);
    case 13..16:    GameTextForPlayer(playerid, "La Costra Nostra Family", 1000, 4);
    case 17..20:    GameTextForPlayer(playerid, "Hitman", 1000, 4);
    case 21..23:    GameTextForPlayer(playerid, "Da Nang Boys", 1000, 4);
    //default is the same as else (all other classids which you didnt used)
    default:        GameTextForPlayer(playerid, "Undefined Class", 1000, 4);
}



Re: redundant test ? - Rks25 - 25.02.2009

Sorry my fault, it should be:
Код:
else if (classid == 5 || classid == 6 || classid == 7|| classid == 8)