ID:178762
 
How could I get this to work when no one/nothing is in an area?



area/grassfield1


proc/whatever()
if(!grassfield1.contents.len)
[whatever]
Gakumerasara wrote:
How could I get this to work when no one/nothing is in an area?



area/grassfield1


proc/whatever()
if(!grassfield1.contents.len)
[whatever]

I believe that turfs are also part of an area's contents, so you might have trouble there. If you just want to check for objects and mobs, try something like this:

proc/whatever()
if (locate(/atom/movable) in contents)
[whatever]
In response to Skysaw
Skysaw wrote:
I believe that turfs are also part of an area's contents, so you might have trouble there. If you just want to check for objects and mobs, try something like this:

proc/whatever()
if (locate(/atom/movable) in contents)
[whatever]


Do you have any idea what I could do to cycle through the mobs in an area? I tried this:


for(var/mob/N in /area/bfield)
if(N in src.party) continue
return 0
return 1


but it always returns 1 (doesn't even go through the for loop). bfield.contents doesn't work for some reason.
In response to Gakumerasara
Gakumerasara wrote:
Skysaw wrote:
I believe that turfs are also part of an area's contents, so you might have trouble there. If you just want to check for objects and mobs, try something like this:

proc/whatever()
if (locate(/atom/movable) in contents)
[whatever]


Do you have any idea what I could do to cycle through the mobs in an area? I tried this:


for(var/mob/N in /area/bfield)
if(N in src.party) continue
return 0
return 1


but it always returns 1 (doesn't even go through the for loop). bfield.contents doesn't work for some reason.

Your loop is not executing because there are no mobs in the type /area/bfield. This is a common beginner's mistake... to supply a datum type when what you really need is a reference to a datum.

How to get the reference depends on the structure of your code. If you have only one bfield area, it's pretty easy:

var/area/bfield/B = locate()

The rest of the code is a little mysterious to me. It looks like it will return 0 if it finds any mob that is not in the src's party. Is that intended? If so, just do this:

var/area/bfield/B = locate()
for(var/mob/N in B)
if(N in src.party) continue
return 0
return 1

But if what you meant to do is just test to see if any mobs are in that area, do this instead:

var/area/bfield/B = locate()
return locate(/mob) in B

Actually, I believe you could even shorten this to:

return locate(/mob) in locate(/area/bfield/B)

But you'll have to test that for yourself.
In response to Skysaw
it worked; thanks a lot :)