Help with the Conditions -
Saw® - 22.06.2012
Hi , i have in my Gamemode like
pawn Код:
if ((weaponid.....) && (gTeam..8))
{
//my stuff here
}
if ((weaponid.....) && (gTeam...9))
{
//my stuff here
}
if ((weaponid.....) && (gTeam...10))
{
//my stuff here
}
it is just an example , well , it is correct ? may i put "else if" instead of the second "if"? & whene can i use "else if" and "if" ?
Thank you .
Re: Help with the Conditions -
.Wicked - 22.06.2012
May I ask? What are you going to do?
Re: Help with the Conditions -
iggy1 - 22.06.2012
It depend what you want to do.
Where do you put that code? And what do you want it to do?
Re: Help with the Conditions -
Saw® - 22.06.2012
I put it under Public onplayerTakeDammage
@.wicked : i'm going to set dammage of players in Team 8 (-5hp) for Team 9 (-7) for Team 10 (- 10)(example)
So the used weapon for all the teams must be 0 (unarmed)(for issuerid of course)
NB: i want to set for each team his privilages. (sorry for my bad english).
Re: Help with the Conditions -
iggy1 - 22.06.2012
Use
else if for better efficiency.
Once the condition has been reached no further
else if conditions will be processed.
Whereas if you use
if; all
if statements will be processed.
Re: Help with the Conditions -
Saw® - 22.06.2012
Thank you ! but how to know if i must use "if" or "else if" ? sorry again..
Re: Help with the Conditions -
iggy1 - 22.06.2012
It depends whether you need the
if statement to be processed whether a condition has been found.
pawn Код:
public OnPlayerConnect(playerid)
{
new var = 5;
if( var == 5 )
{
}
if( var == 10 )//this will be processed even if you have already determined that var isn't 10
{
}
return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
new var = 5;
if( var == 5 )
{
//because this is executed any following "else if" will not be processed.
}
else if( var == 10 )//this will not be processed if any statement above has been executed
{
}
return 1;
}
It really doesn't matter too much normally, but it's good practice to use
else if where possible.
You can find out more and get a much better description than i have given in almost any programming book. Most languages have
if else if statements. If you know what "else" means in English you should have a fairly good understanding of what
else if does.
Re: Help with the Conditions -
Saw® - 22.06.2012
Thank you eggy1 ! you helped me a lot ++rep ! i will use else if statment.