ID:172380
 
I was just wondering if this is a safe way to code this. If not can you tell me a better way please.What im trying to do is check if there is a item in the player and if there is delete it.
if(locate(/obj/Items/Food/Apple) in usr)
var/obj/Apple = locate(/obj/Items/Food/Apple) in usr.contents
del Apple
Turles9000 wrote:
I was just wondering if this is a safe way to code this. If not can you tell me a better way please.What im trying to do is check if there is a item in the player and if there is delete it.
if(locate(/obj/Items/Food/Apple) in usr)
> var/obj/Apple = locate(/obj/Items/Food/Apple) in usr.contents
> del Apple


That should work fine in a verb. If it's not in a verb, you shouldn't use usr, though.

Here's a better way:
var/obj/Apple=locate(/obj/Items/Food/Apple) in usr.contents
if(Apple) del(Apple)


It does the same thing, but it keeps it from having to locate() it twice.

~>Volte
In response to Volte
Thanks but Is there a problem with having locate twice or is it just that its a waste of space
In response to Turles9000
Turles9000 wrote:
Thanks but Is there a problem with having locate twice or is it just that its a waste of space

It won't cause errors or anything, but it's just a longer, less efficient way.

~>Volte
In response to Volte
K Thanks again