Problem description:
So I have talk verb. I want an if condition that checks for a certain item in this persons inventory. In this case it's an obj/item/scroll/letterforgruwald. How do I incorporate that into an if statement?
![]() Apr 6 2015, 3:37 pm
Best response
|
|
Alternatively, you can cast more specifically and use locate()'s documented shorthand (and also name your variables better):
var obj/item/scroll/letterforgruwald/letter = locate() in usr |
That makes sense. I get screwed up with the conditions a lot. Thank you guys, though. Much appreciated!
|
Or you can turn it into a one liner, and prevent useless scopes...
if(!(locate(/obj/item/scroll/letterforgruwald) in src)) return |
I have a feeling this letter is going to be deleted or something, so a reference to it will be used. Otherwise, yeah, useless or one-time-use variables should be avoided unless it makes the code clearer for the reader.
It looks to me like a delivered quest item, but that's a guess. |
I never really enjoyed the use of locate() other than for grabbing locations on the map, although I know there's a lot more functionality for it than that given Kaiochao's suggestions above. I think I would probably do it this way:
for (var/obj/item/scroll/letterforgruwald/a in src.contents) |
Mr_Goober wrote:
I never really enjoyed the use of locate() other than for grabbing locations on the map, although I know there's a lot more functionality for it than that given Kaiochao's suggestions above. I think I would probably do it this way: > for (var/obj/item/scroll/letterforgruwald/a in src.contents) But then you're creating an unnecessary loop through all of the mob's contents which isn't exactly efficient especially if you've got ten people all doing the same quest or whatever runs the process at the same time. |