ID:270496
 
How would you check to see if all objects of a type all have the same var value? For example, you have 5 apples in the world, and they all have a delicious var. How would you check to make sure that all of them don't have delicious=0?
for(var/obj/apple/A in world)
[tab]if(!A.delicious) //error code here

I think something like that?
proc
CheckApples()
var/failsafe
for(var/obj/apple/a in world)
if(a&&!a.delicious)
failsafe=1
break
if(failsafe)
world << "Uhoh, there must be a problem in the apple tree!"


You could also get rid of the failsafe part and just stick it in the for line, but I felt this way would be better.
In response to Justin B
I figured out this on my own but I went out so I didn't have a chance to post it.

var
b
c
d
for(var/obj/apple/a in world)
b++
if(!a.delicious)
c++
else
d++
if(b==d)
world<<"All apples are delicious!"
else if(c>d)
world<<"There are more non-delicious apples than delicious apples!"
else if(d>c)
world<<"There are more delicious apples than non-delicious apples."


Not a simple for() loop or a bail-out loop if something is wrong, but it compares how many total objects to those who have the var or !var.

I believe I was thinking more on how to compare the vars between the five objects instead of looping through them and counting.