SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 25/11/2012, 03:59 PM   #1
Channeru
Little Clucker
 
Channeru's Avatar
 
Join Date: Nov 2012
Posts: 8
Reputation: 2
Default IF or SWITCH?

Hi everyone. I want to ask you what is better to use.

In callback OnPlayerSpawn i have random spawn function which detect position by Team

pawn Code:
if (Team == T_MEDIC)
    {
        SetPlayerPosEx(playerid, MedicPos[Pos][0], MedicPos[Pos][1], MedicPos[Pos][2], MedicPos[Pos][3]);
    }
    else if (Team == T_FARMER)
    {
    ....

should i use switch, or if ?
pawn Code:
switch(Team)
{
    case T_MEDIC: SetPlayerPosEx(playerid, MedicPos[Pos][0], MedicPos[Pos][1], MedicPos[Pos][2], MedicPos[Pos][3]);
    case T_FARMER: ....
Channeru is offline   Reply With Quote
Old 25/11/2012, 04:04 PM   #2
Nordic
Little Clucker
 
Join Date: Nov 2012
Location: United States
Posts: 35
Reputation: 16
Default Re: IF or SWITCH?

how many cases do u have
Nordic is offline   Reply With Quote
Old 25/11/2012, 04:08 PM   #3
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,828
Reputation: 1401
Default Re: IF or SWITCH?

I use switch only in large parts. If it's a part with 2 lines, if this, else I will use if/else statement.
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos is offline   Reply With Quote
Old 25/11/2012, 04:15 PM   #4
Crypt
Little Clucker
 
Join Date: Nov 2012
Posts: 12
Reputation: 0
Default Re: IF or SWITCH?

Mostly "switch" is faster then "if/else" statements, but you can't use it everywhere.
Crypt is offline   Reply With Quote
Old 25/11/2012, 04:19 PM   #5
Channeru
Little Clucker
 
Channeru's Avatar
 
Join Date: Nov 2012
Posts: 8
Reputation: 2
Default Re: IF or SWITCH?

Yes this is so large... so i'll use switch thank you
Channeru is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
switch Speed Scripting Help 4 28/10/2011 06:10 PM
Switch + else? CrucixTM Help Archive 2 18/10/2010 08:23 PM
Why can I not do this switch? Memoryz Help Archive 2 13/09/2010 08:17 PM
Switch Help Mini` Help Archive 0 02/03/2010 11:06 PM
Switch VS IF Luka P. Help Archive 13 22/11/2009 08:51 PM


All times are GMT. The time now is 06:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.