ID:266537
 
mob/verb/Test()
if(usr.contents.Find(/obj/hello,1,0))
usr<<"Hi!"

ok i have a /obj/hello in my contents but it dosn't say hi back?

i also tried this but it didnt work


mob/verb/Test()
for(var/n in usr.contents)
if(n==/obj/hello)
usr<<"Hi!"
Strange Kidd wrote:
mob/verb/Test()
if(usr.contents.Find(/obj/hello,1,0))
usr<<"Hi!"

ok i have a /obj/hello in my contents but it dosn't say hi back?

This is because the items in your usr.contents list are actual objs, not type paths. If the list was a list of type paths, then this would work, but it's not.

i also tried this but it didnt work

mob/verb/Test()
for(var/n in usr.contents)
if(n==/obj/hello)
usr<<"Hi!"

That's the same problem. The statement if(n==/obj/hello) will always be false here because every value of n will be an atom (an obj), not a type path.

There are two ways to fix this. The worst way is to modify the n==/obj/hello line:
  if(istype(n,/obj/hello))

OR:
for(var/obj/n in usr.contents)
if(n.type==/obj/hello)

The best way to change this is to loop through only objects of type /obj/hello, which you can do:
for(var/obj/hello/n in usr.contents)
usr << "Hi!"

Lummox JR
In response to Lummox JR
would it work the same way if you replaces contents with verbs?
In response to Strange Kidd
There's a proc that's meant for searching procs/verbs; it's called hascall() check it out. But yes the example you were just shown can be used for verbs with some modification to it.
In response to Strange Kidd
Strange Kidd wrote:
would it work the same way if you replaces contents with verbs?

Here's the funny part: The verbs list actually is made of type paths, so the code you had would work for that (although you'd have to search for things like /mob/verb/Jump instead) even though it didn't work for usr.contents.

Although it doesn't have to be this way, lists usually contain only one type of thing. A contents list contains atoms; if you want to find a specific one, Find() or == will do, but if you want to find one by its object type you should use a for() loop, locate(), or istype(). The verbs list is actually made up of type paths pointing to various procs, so == and Find() are perfectly appropriate.

(I didn't mention locate() in my last post, but it basically would work like this:
var/n = locate(/obj/hello) in usr.contents

The locate() proc is pretty versatile.)

Lummox JR