ID:1511804
 
(See the best response by Nadrew.)
Code:
obj
Brew_Items
var/SellPrice
Mater_Brew
desc = "A bitter tasting brew used to restore 20 Stamina."
icon = 'Brews.dmi'
icon_state = "Mater Juice"
verb
Drink(var/obj/Brew_Items/Mater_Brew/O in usr)
set category = null
set popup_menu= 1
usr.Stamina += 20
usr.UpdateStamina()
del(O)
usr<< "You gain 20 Stamina!"


Problem description:
Why is it when I have other objects in my inventory that are defined as /obj/Tools/Garden_Hoe as you can tell totally different paths, why is it when I click the verb drink on a brew it pulls up a list of all items in my inventory?

Best response
Well, for one verb arguments don't really know anything besides the top-most type of the atom, so it's not gonna be able to differentiate between them (it's basically the same as using 'obj/O in usr'.

For two, you don't need a verb argument at all, since you're using the verb on an object of that type already.

verb
Drink()
set category = null
set popup_menu = 1
set src in usr // Important
if((!src in usr)) return // Just in case
usr.Stamina += 20
usr.UpdateStamina()
usr << "You gain 20 Stamina!"
del(src) // Remove the object you used the verb on.
Thank you. I didn't know that typing out a defined path to a atom would end up not being "defined" at all but more general.
Verb arguments of that nature aren't very robust, if they were they'd probably be slow at runtime, if you do need a way to select a specific type of item from your inventory you're probably better off doing it manually:

var/list/myitems = list()
for(var/obj/my_obj/O in usr)
myitems += O
var/obj/my_obj/selected = input("What item do you want to pick?")as null|anything in myitems
if(!selected) return
usr << "You picked [selected.name]!"


Keep in mind though, that these objects most likely share a name, so they'll only appear once on the list, so you have to get a little more complicated, making the indexes unique.

var/list/myitems = list()
var/pos = 0
for(var/obj/my_obj/O in usr)
myitems["[++pos] [O.name]"] = O
var/selected = input("Which item do you want to pick?")as null|anything in myitems
if(!selected) return
var/obj/my_obj/actual_selected = myitems[selected]
usr << "You picked [selected] ([actual_selected.name])!"
Gotcha! Thanks again.
In response to Nadrew
Nadrew, I have one more question for you. Why is this returning a runtime error of cannot read null.verb.
proc
AddBuyVerb()
var/obj/O
O.verbs += /obj/Brew_Items/Mater_Brew/verb/Buy
area
Brew_Area_Enter
Entered(mob/M)
M.InShop = 1
M.loc = locate(6,2,2)
AddBuyVerb()
usr << "Welcome to The General Supplier here for all your farming needs!"
In response to The WardenX
When you say var/obj/O, you're declaring a variable named O of type /obj. Because you've only declared it and not defined it, O is equal to null, so you're trying to add a verb to a non-existent object.

With that said, even if AddBuyVerb() worked (all you need to do is create a new instance of O), it won't really do much of anything because it'll add the verb to O, then immediately garbage collect O because it's no longer in scope.

If you're wanting to add a verb to something via a procedure, you could do something like...

proc/add_verb(mob/m)
m.verbs += /mob/verb/Say

area/talk_zone/Entered(mob/m)
m << "You can talk now!"
add_verb(m)

(Also, you shouldn't use usr in Entered(). Use M instead since you already have it set up).