I'm trying to make it so when you click the verb "Search" it searches for whoever's name is "Bob" and says "You found bob!" And if no one is named "Bob", it says "Bob was not found...".
I tried to do this with the for() proc, but I don't want it to check each player in the server and say if they're Bob or not, like:
Bob was not found...
Bob was not found...
Bob was not found...
You found Bob!
Bob was not found...
I was thinking the for() proc wasn't used in a situation like that, but I'm not sure.
ID:162809
Nov 23 2007, 8:13 pm
|
|
You should put an if() statement(tabbed) under the for() loop, and if Bob is found, say so. If not, say not.
|
In response to Kaiochao2536
|
|
Wow that was a fast reply. Thanks a bunch guys, can't believe I never thought of that.
|
In response to Infusions
|
|
Yeah I was already here posting my own devoloper how-to topic, so might as well reply to yours since it is easy
|
In response to Infusions
|
|
if() statements make the world go "hmm".
|
In response to Bakasensei
|
|
Gah, bad! You never use a single space for indentation.
|
In response to Bakasensei
|
|
mob/verb/FindBob() Cleaned up a little. |
As long as there is only one of each name you're searching for in the world, you could use tags to speed things up considerably. Just set someone's tag variable to equal their name, and then use locate(src.name) to locate them instantly.
var/list/used_names = list() Then you can do this... mob/verb/LocateMob(mob_name as text) Which is a lot faster and easier than this... mob/verb/LocateWithFor(mob_name as text) Note that I use lowertext() when storing the names so that there's no capitalization issues when searching for them. Also note that you'll have to do a bit more work than this if you want a saved name list - or if you just go by everyone's key name, you don't have to worry about it. Still, its probably a lot easier to just keep a list of all the players if you're searching for players, and then you can still use a for() loop to find them, but instead of looping through the whole world (thousands of objects), you're just looping through a couple dozen at best. |
Tested and fixed, it works perfect.