Raised This Month: $ Target: $400
 0% 

question about enums and switch


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-20-2012 , 02:07   Re: question about enums and switch
Reply With Quote #1

Why don't you test it? And yes switch statements are more efficient than using "if" multiple times.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 05-20-2012 , 10:35   Re: question about enums and switch
Reply With Quote #2

Quote:
Originally Posted by hornet View Post
Why don't you test it? And yes switch statements are more efficient than using "if" multiple times.
switches are easier to code too.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 05-21-2012 , 13:42   Re: question about enums and switch
Reply With Quote #3

PHP Code:
enum Weapon
{
    
Deagle,
    
AWP,
    
Knife,
    
Grenade,
    
Scout,
    
SG550,
    
G3SG1,
    
AK47,
    
M4A1
}
new 
gWeapon[MAX_PLAYERS 1][Weapon]

new const 
gNames[Weapon][10] =
{
    
"Deagle",
    
"AWP",
    
"Knife",
    
"Grenade",
    
"Scout",
    
"SG550",
    
"G3SG1",
    
"AK47",
    
"M4A1"
}
new 
Weapon:gName[MAX_PLAYERS 1
Usage:
PHP Code:
gWeapon[id][Deagle] = true 
PHP Code:
if(gWeapon[id][Deagle])
        
gName[id] = Deagle 
PHP Code:
switch(gName[id])
{
     case 
Deagle:
          {
                
// Do something
          
}

Is this right ?
__________________

Last edited by Alekkkk; 05-21-2012 at 14:08.
Alekkkk is offline
Send a message via Skype™ to Alekkkk
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-21-2012 , 14:00   Re: question about enums and switch
Reply With Quote #4

More correct code would be :

new Weapon :gWeapon[MAX_PLAYERS + 1]

And then :

gWeapon[id] = Deagle

Considering a player can be in only once duel type at the same time.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Alekkkk
Member
Join Date: Mar 2012
Location: Bulgaria
Old 05-21-2012 , 14:14   Re: question about enums and switch
Reply With Quote #5

fixed
PHP Code:
new Weapon:gName[MAX_PLAYERS 1
this part. (That was my fault)

If i set only gWeapon[id] = Deagle , can i use it in print_chat like that:

PHP Code:
client_print_color(0Red,"%s"gWeapon[gName[id]]) 
Edit:
I can't set gWeapon[id] = Deagle (Error : Array must be indexed)
When i set gName[id] = Deagle , i can use it in chat : client_print_color(0, Red,"%s", gNames[gName[id]])
I think it is solved .
__________________

Last edited by Alekkkk; 05-21-2012 at 15:29.
Alekkkk is offline
Send a message via Skype™ to Alekkkk
Reply



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

Forum Jump


All times are GMT -4. The time now is 00:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode