ID:178650
 
I'm haveing trouble getting this verb to work, any help is appreciated.
mob
verb

Use()
var/list/owitems = new()
var/tempval
var/useitem
for(var/x in usr.contents)
owitems += x
owitems += "Cancel"
if (owitems.len == 1)
usr << "You don't have any items"
else
useitem = input("Which item would you like to use?") in owitems
usr << "[useitem]"
switch(useitem)
if("Cancel")
return ..()
if("Herb")
tempval = usr.maxhp - usr.hp
if(tempval >= 20)
usr.hp += 20
tempval = 20
else
usr.hp += tempval
usr << "You were healed for [tempval] HP."
else
usr<<"[useitem]"
usr << "This item has no effect"

-----

useitem comes up as 'Herb', but it goes right to no effect.

Thanks
What you are doing is creating a list of objects, and then checking to see if it equals a text string. Since objects aren't text strings, the else in the switch is triggered. Your should look like:
[snip]
useitems = input("What item will you use?")in owitems
if(useitems == "Cancel")
return //this ends the proc
if(istype(useitems,/obj/herb))
blah blah blah...
return
usr << "This item has no effect"
[snip]

That is one way of doing it. There is, however, a much more efficient way of doing that. This is the way I would code your verb.
obj/verb/Use()  //Define a use verb for an obj

obj/herb/Use() //Make the herb's use verb special for the herb
set src in usr //Only make the verb pop up when the herb is in usr's inventory
usr << "You use the herb!"
usr.hp += 20
if(usr.hp > usr.maxhp)
usr.hp = usr.maxhp //Make sure hp doesn't exceed maxhp
usr << "You gain 20 HP!"
del(src) //Delete the herb so you can't keep using it over and over again

Hope that helped.