ID:317542
 
(See the best response by Kaiochao.)

obj/torch/verb/put_out()
set src in view(1)
src.luminosity=0

obj/torch/verb/light_up(var/obj/matches/m, var/mob/p)
set src in view(1)
if(m in p.contents)
if(src.luminosity==0)
src.luminosity=3

obj/matches
icon='matches.dmi'


Problem description: I am trying to make it so that the torch will only be lit up only if the player has matches but it doesn't seem to work. Alternatively if I do change to this:

   if(m in view(1))
the torch lights up all the time when I wanted it only to be if its around matches.

What did I do wrong?
Best response
For verbs like this, it is necessary to use usr, because that would probably be the only 99% sure way to tell who performed the action.
obj/torch/verb/light_up()
set src in view(1)
if(locate(/obj/matches) in usr)
// ...

view() actually has usr as its center by default (check the reference), which is why your other method works properly (and the src setting works the way you have it).
I think you're misunderstanding how verb arguments work. Anyways, you don't want them in this case. When a player uses a verb that exists on another object via the set src in ... setting, the player's mob is passed as the usr in said verb. The match you'll have to use locate() to search for in the player's contents.

obj/torch/verb/light_up()
set src in view(1)
var/obj/matches/m = locate(/obj/matches) in usr.contents
if(m)
if(src.luminosity==0)
src.luminosity=3


locate() will implicity pick up /obj/matches from the variable m's type, but I passed it the value anyways for clarity.

<edit>
Ah, ninja'd!