ID:146218
 
Code:
mob/proc/Locate()
for(var/obj/dragonballs/Dragonball_1/a in src.z)
if(!a in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [a.x],[a.y]"
for(var/obj/dragonballs/Dragonball_2/b in src.z)
if(!b in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [b.x],[b.y]"
for(var/obj/dragonballs/Dragonball_3/c in src.z)
if(!c in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [c.x],[c.y]"
for(var/obj/dragonballs/Dragonball_4/d in src.z)
if(!d in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [d.x],[d.y]"
for(var/obj/dragonballs/Dragonball_5/e in src.z)
if(!e in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [e.x],[e.y]"
for(var/obj/dragonballs/Dragonball_6/f in src.z)
if(!f in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [f.x],[f.y]"
for(var/obj/dragonballs/Dragonball_7/g in src.z)
if(!g in src.z)
src<<"Dragonball isn't in this map or someone has it!"
else
src<<"Dragonball 1 is located: [g.x],[g.y]"


Problem description:
I want to make it so when I call this proc, it will locate all the DBS in the src's Z level, but when I activate it, it doesn't work.

What did I do wrong?

for(var/ref/o in block(locate(1,1,z),locate(world.maxx,world.maxy,z)))

Try that.
In response to Ol' Yeller
Ungh. No! That's so much extra processing for no reason. A simple:
var/obj/DragonBall1/D1
for(D1 in world)break
if(D1&&D1.z==z)world<<"YAY!"

Also, it's stupid that you gave each dragonball their own type path. Just make them all /obj/Dragonball, and give them a 'value' variable to differ each one.
In response to Crashed
"for(D1 in world)break"
_>
Isn't that even more processing?
In response to Ol' Yeller
Don't think so, I think block() would have to loop through every turf anyway.
In response to Ol' Yeller
Ol' Yeller wrote:
> for(var/ref/o in block(locate(1,1,z),locate(world.maxx,world.maxy,z)))

Try that.

Uh, /ref is a datum, not an atom. Besides, unless it's a turf, it won't appear in block(). That's a common pitfall of block(): You have to loop through every turf to find objs and mobs.

Lummox JR
Crzylme wrote:
What did I do wrong?

Here's the problem:
for(var/obj/dragonballs/Dragonball_1/a in src.z)


src.z is a number. Hence you're saying for(a in 1), which is ridiculous.

Another problem:
if(!a in src.z)


If you're going to use the in operator--in this case it's the same problem with src.z, but let's assume that part was correct--you need to put parentheses around it if you use other operators like !. That should be if(!(a in list)).

A final problem is design. You're going to get 7 different messages every time when it would make more sense to simply loop through all the dragonballs and check their z level against the player's z, then report them if found. If none are found, then you can output a default message.

Lummox JR
In response to Lummox JR
Well, I met ref so he could replace it with something... =/
I didn't even know it was a datum. <_<