ID:265673
 
I like to know which would be more efficient.

#1
mob/verb/fire()//standard verb
switch(usr.weapon)
if("Dual UMP45")
usr.Fire_Weapon()
if("Dual Uzi")
usr.Fire_Weapon()
if("Dual MP5")
usr.Fire_Weapon()


#2
mob/verb/fire()//standard verb
if(usr.weapon=="Dual UMP45"||usr.weapon=="Dual Uzi"||usr.weapon=="Dual MP5")
usr.Fire_Weapon()//Run a fire proc


Would using #1 be more efficient than using #2?
#2 is more like it... or
const/var/guns=list("Dual UMP45","Dual Uzi","Dual MP5")  //A list of firable weapons
mob/verb/fire()
if(usr.weapon in guns) //if the weapon of the user is found in the list
usr.Fire_Weapon()
That is assuming you'll have a huge amount of guns using the same procedure >_>

Really though, you should make the variable weapon refer to the gun item itself (if it's in the user's content)
mob/var/obj/gun/weapon
obj/gun/pistol/verb/Hold() usr.weapon=src
than you'd search for the name
if(usr.weapon.name ...


- GhostAnime
In response to GhostAnime
GhostAnime wrote:
#2 is more like it... or
const/var/guns=list("Dual UMP45","Dual Uzi","Dual MP5")  //A list of firable weapons
> mob/verb/fire()
> if(usr.weapon in guns) //if the weapon of the user is found in the list
> usr.Fire_Weapon()


using a list and the in operator makes the code a lot shorter, but it doesn't make the process any less complex. it still has to check if usr.weapon is guns[1], or if usr.weapon is guns[2], etc. until it finds a match. its done internally if you use a list, so there might be a slight advantage, but its still not much better. the more guns you have the longer it can take.

Really though, you should make the variable weapon refer to the gun item itself (if it's in the user's content)

the gun doesn't have to be in usr.contents, it could exist anywhere. as long as it exists you can have a reference to it.

if you make usr.weapon a reference to the gun object you can just give the fire() proc to the weapon and say:
mob/verb/fire()
if(usr.weapon)
usr.weapon.fire()

this way you don't have to figure out which gun the user has equipped, you already know it and you can directly call the correct fire proc for the gun.
In response to OneFishDown
Ok the gun system I have uses diffrent types of bullets and ammo for each weapon, Shotguns, Handguns, etc.... so list would do fine thx.

- Dark Emrald