How do I make a for loop check from top to bottom until it finds what it needs and if it doesnt find what it needs it displays src << "Cannot find [blah]"
Ex.
mob/verb/Find()
for(var/obj/key/A in src.contents)
A = anything in typesof(usr.contents)
if(Found.key.A && A.HiddenKey == usr.key)
src << "Found [A]"
else
src << "Cannot find [A]"
ID:266751
Jun 12 2002, 6:31 pm
|
|
In response to Gazoot
|
|
Gazoot I know that but it was an Ex. how do I get it to check every single thing before it does anything? or something like that?
|
I'm not sure exactly what you want but I think this is the direction your heading:
var/key/K for(K in contents) if(K.ishidden) //do something break if(!K) src << "Nothing useful was found!" If you exit a loop normally the variable you were using will be null (thus the !K). If, however, you break out of the loop, K will keep the last value it had so it won't be null. |
In response to English
|
|
Thanks!
|
In response to Thief Jack
|
|
Thief jack wrote:
Gazoot I know that but it was an Ex. how do I get it to check every single thing before it does anything? or something like that? If you know that I don't see what the problem is. But instead of a for loop, I would rather use locate() to check for an item in a list. var/obj/bonsai/B = locate() in src.contents // Check for a bonsai tree in the inventory This is the same example as in the help file. Read more about locate there. |
You're starting out fine, but remember that A is already assigned to the first key in the contents list. So you don't need the "A =" line. Also, if you don't have A in your list the for loop will never execute.
/Andreas