ID:175105
 
Another for loop problem, eh...

This time I'm trying to loop through all the obj's in the world, and find out what the "amount" is. Here is the code...

mob/verb
CheckObjects()
for(var/obj/S in world)
usr<<"There are [S.amount] [S]"

obj/var
amount

obj
Apples
amount = 1000
<dm>

All help is appreaciated.
I'm not quite sure what you're trying to do here, find the combined value of all apple amounts in the world?

<code>var/combined = 0 for(var/obj/apple/A in world) combined += A.amount usr << "[combined] apples total"</code>

Find the total amount of apple objects in the world?

<code>var/total = 0 for(var/obj/apple/A in world) total++ usr << "[total] apples in the world"</code>

Or what? If you just want to look through all the apples in the world and see what their amount is, I see nothing wrong with the code you've got.
In response to Foomer
Foomer wrote:
Or what? If you just want to look through all the apples in the world and see what their amount is, I see nothing wrong with the code you've got.

That's exacly what I'm trying to do and its not working. Whenever I click the verb nothing happens. I don't understand what is wrong.
In response to SSChicken
Maybe you never placed any objects on the map. Or maybe you didn't make any new() objects. Objects merely defined in your code are not in the world.
In response to Jon88
Ooh, right I forgot about that. Haha, I'm not placing any objects on the map, so I guess I'm going to have to use the New() command.

Wait...so is there an easy way to make a new object when starting the world. I think it should loook something like:

world/New()
new object here


but I'm not sure..
In response to SSChicken
Yeah.
world
New()
..() //Very important.
new /obj (locate(1,1,1))
In response to DarkView
world 
New()
..()
new/obj/Apples(1,1,1)


That's what I have. It dosn't give me any errors, but still dosn't work with the for loop.
In response to SSChicken
Because it should be new/obj/apples(locate(1,1,1))
In response to Nadrew
Eh...still dosn't work. Maybe I missed something.

world 
New()
..()
new/obj/apples(locate(0,0,0))

mob/verb
CheckPrices()
for(var/obj/S in world)
usr<<"There is [S.amount] of [S]"

obj/var
amount

obj
apples
amount = 1000
In response to SSChicken
Location 0,0,0 doesn't exist, it's null..
In response to Nadrew
Those 3 values represent the x, y and z co-ordinates on the map. If you take a look in the map editor there are 3 numbers next to the map, those are the current co-ordinates the mouse is over.
In response to DarkView
Yes, I knew that, but then I didn't think it would work because I don't have a world map. Now let me check...aah, my problem was that I didn't have a map. Well thank you all very much, it works! ^_^