ID:259492
Apr 4 2002, 4:35 am
|
|
Like whaere a code like if(usr.contents.Contains(/obj/flashlight)
|
Apr 4 2002, 4:36 am
|
|
Look up Find() and for()
|
In response to Nadrew
|
|
Nadrew wrote:
Look up Find() and for() As his post on Newbie Central demonstrates, I think you confused him with Find(); it's not appropriate for this situation (although locate() would be). Lummox JR |
In response to Lummox JR
|
|
His Contains() proc would have worked alot like Find() so I recommended he look it up. locate() so is the example you posted in Newbie Central. I just wanted him to know a proc like the one he requested was already there.
|
In response to Nadrew
|
|
Nadrew wrote:
His Contains() proc would have worked alot like Find() so I recommended he look it up. locate() so is the example you posted in Newbie Central. I just wanted him to know a proc like the one he requested was already there. But Find() isn't at all correct for searching for items of a specific type in a list, which was my point. Find() is only appropriate for situations where you'd loop through checking if A==B, not istype(A,B). locate(), however, can search according to the type of its expected return value. Lummox JR |
In response to Lummox JR
|
|
Lummox JR wrote:
Nadrew wrote: Locate is also nice in that it will return a reference to the object, if you need it: mob/proc/flashlight_on() var/flashlight/F = locate (/obj/flashlight) in usr.contents if(F) F.turn_on() else usr << "You don't have a flashlight!" A silly example, since the verb should be on the flashlight itself, but you get the idea. |
In response to Lummox JR
|
|
Oops, I had almost completely forgotten that you can use locate like that for any container. That will cut down on some of my code in my current project because I have the ants look arround them every once in a while for food, other ants, ect.
|