Raised This Month: $ Target: $400
 0% 

what is faster? switch or an array?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Speed!
BANNED
Join Date: Jan 2009
Old 03-31-2009 , 13:41   what is faster? switch or an array?
Reply With Quote #1

PHP Code:
damage *= weapon_damage[get_weapon_id.... 
or
PHP Code:
switch (get_weapon_id...
{
case 
CSW_DEAGLEdamage *= 
which is better? this would be called in ham_takedam
Speed! is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-31-2009 , 13:46   Re: what is faster? switch or an array?
Reply With Quote #2

I guess the first.
Arkshine is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-31-2009 , 13:49   Re: what is faster? switch or an array?
Reply With Quote #3

I always use an array for something like that.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Speed!
BANNED
Join Date: Jan 2009
Old 03-31-2009 , 14:03   Re: what is faster? switch or an array?
Reply With Quote #4

I don't really know, coz 1 method requieres more functions to be called in order to obtain the weapon id, etc... Actually I don't really know how to make it work the first method, since this needs something like weapon_deagle instead of CSW_DEAGLE...
Could anyone help me?
Speed! is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-31-2009 , 14:35   Re: what is faster? switch or an array?
Reply With Quote #5

Quote:
Originally Posted by Speed! View Post
I don't really know, coz 1 method requieres more functions to be called in order to obtain the weapon id, etc... Actually I don't really know how to make it work the first method, since this needs something like weapon_deagle instead of CSW_DEAGLE...
Could anyone help me?
http://www.amxmodx.org/funcwiki.php?go=func&id=1081
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-31-2009 , 16:24   Re: what is faster? switch or an array?
Reply With Quote #6

Where do you get the weapon name ?
You should be able to retrieve directly weapon id. (if attacker = inflictor, use get_user_weapon )
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-31-2009 , 14:10   Re: what is faster? switch or an array?
Reply With Quote #7

Use switch.
__________________
hleV is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-31-2009 , 14:14   Re: what is faster? switch or an array?
Reply With Quote #8

Array good to use because:
-> fast access
-> easy to write
Bad:
-> uses memory unfortunately

Switch:
Good:
-> doesn't use memory
Bad:
-> hard to write (sometimes)

In this case I would advise the first ...
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
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 02:20.


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