SA-MP Forums Archive
if , itches my brain - 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: if , itches my brain (/showthread.php?tid=279096)



if , itches my brain - cmg4life - 25.08.2011

I kinda' forgot this, but with Pickupid & Dialogid, is it better to do if( pickupid ) else if ( pickupid ) or just if ( pickupid ) then if ( pickupid ) ?

What's more efficient, laggyless and so on ?


Re: if , itches my brain - Johndaonee - 25.08.2011

use
pawn Code:
switch( dialogid )
   {

   }



Re: if , itches my brain - cmg4life - 25.08.2011

Can't use "switch", i'm stuck between "if" and "else if" .


Re: if , itches my brain - WooTFTW - 25.08.2011

if(pickupid)
else if(pickupid)

is more efficent.

But if you can, you should
switch(pickupid)


Re: if , itches my brain - Mean - 27.08.2011

Nothing is more efficient as far as I know. They both work and "else" is kinda useless here.

But, if you are that concerned about the correctness, use else if. I don't see how "if" and then "if" can fail though.

By the way: I don't see how you can be stuck with "if". o_O


Re: if , itches my brain - Kingunit - 28.08.2011

I always use just "if" "if" "if". I don't see the point of "if" "else if" "else if"


Re: if , itches my brain - lolumadd_ - 28.08.2011

Quote:
Originally Posted by Kingunit
View Post
I always use just "if" "if" "if". I don't see the point of "if" "else if" "else if"
The point of using else if is so that if one statement above it is true, it wont continue to the next statement and continue to check.

I'm guessing you can't use switch because the pickup id's aren't static (pickup id's are assigned to variables).

And to answer your question, for dialogs (since dialogs are static id's), you should use a switch statement.
And for the pickups, if you aren't going to use static id's, it is recommended to do a
Code:
if
else if
else if
type structure.


Re: if , itches my brain - =WoR=Varth - 28.08.2011

Quote:
Originally Posted by lolumadd_
View Post
The point of using else if is so that if one statement above it is true, it wont continue to the next statement and continue to check.

I'm guessing you can't use switch because the pickup id's aren't static (pickup id's are assigned to variables).

And to answer your question, for dialogs (since dialogs are static id's), you should use a switch statement.
And for the pickups, if you aren't going to use static id's, it is recommended to do a
Code:
if
else if
else if
type structure.
Of course they are static. https://sampwiki.blast.hk/wiki/CreatePickup
And I recommend him to use switch for pickup:
pawn Code:
public OnPlayerPickUpPickup(playerid,pickupid)
{
    switch(pickupid)
    {
        case House: //...............
        case Weapon:
        {
            //.................
        }
    }
    return 1;
}



Re: if , itches my brain - AndreT - 28.08.2011

Dialog IDs are perfectly static though so the performance there can be improved by using switch!