ID:2035230
 
Code:
mob
icon='Peeps.dmi'
proc
TD()
if(src.z>1)
for(src.z-=1)
world<<"HELLO LOWER"
icon_state="BOT"
for(src.z)
//world<<"HELLOW MID"
icon_state="Normal"
if(src.z<7)
for(src.z+=1)
world<<"HELLO UPPER"
icon_state="TOP"
New()
..()
TD()


Problem description:

I'm having a problem, and it seems to be the TD() being called that make the icons disappear. These are for icons that are placed on the map as NPC. I figured that proc would be the best way to do this since I always want it on.
I'm not even sure what it is you are trying to do, but your use of for() is wrong. Some examples:

// iterating over a fixed range
for(var/iteration in 1 to 10)

// OR, a for() loop using the 'step' keyword.
// this loop counts up by 2 every iteration, which outputs: 1, 3, 5, 7, 9
for(var/iteration in 1 to 10 step 2)

// OR

for(var/iteration = 1 to 10)

// OR

for(var/iteration = 1; iteration <= 10; iteration++)

// OR

// iterating through a container
for(var/mob/m in all_players)
// ...





Your proc changes the icon_state of every mob that's created, not just AI types. If the mobs do not have the icon_state specified, they will default to the last instance (iirc) of a blank state found in their icon. If there is no blank state to fall back on, they will appear blank/invisible.

Let's say you wanted to find all players one map above you when you call a verb named find_players(). You could do something like this:

var global
all_players[] = list()

mob/player
Login()
..()
all_players += src

Logout()
all_players -= src

// allow the mob to be garbage collected
key = null
loc = null

verb/find_players(z_level as null|num)
if(!z_level) return

for(var/mob/player/m in all_players)
if(m.z != z_level)
continue

src << "Found [m] on z level [z_level]!"


Edited to add the supercall to Login().
@FKI: Don't forget to call the supercall in login, or you break the default login procedure.
In response to Ter13
Ter13 wrote:
@FKI: Don't forget to call the supercall in login, or you break the default login procedure.

Good catch. My own habits oversaw the safety of the beginner.
Oh, hmmm, I suppose. Basically what I'm doing is making a person visible on three z-level. Well, mainly that.
In response to Ash Abe Add
Ash Abe Add wrote:
Oh, hmmm, I suppose. Basically what I'm doing is making a person visible on three z-level. Well, mainly that.

Not entirely sure what you mean here.

So, I create a map with 5 z-levels, and create a mob with "Feet", "Body", and "Head" icon states. Then I put a mob on z-level 2. So when I'm on z-level 2, I should see the "Body". If I go down to z-level 1, in that spot I should see the "Feet" in the same spot as the "Body" was. The same thing with z-level 3 seeing the "Head". I would somehow need to use the src.z(++ or --) in order to add these other states, but as you pointed out for() wouldn't work that way.
In response to Ash Abe Add
Ash Abe Add wrote:
So, I create a map with 5 z-levels, and create a mob with "Feet", "Body", and "Head" icon states. Then I put a mob on z-level 2. So when I'm on z-level 2, I should see the "Body". If I go down to z-level 1, in that spot I should see the "Feet" in the same spot as the "Body" was. The same thing with z-level 3 seeing the "Head". I would somehow need to use the src.z(++ or --) in order to add these other states, but as you pointed out for() wouldn't work that way.

It's do-able through other means, but I'm wondering why you want to do that. Mind explaining the purpose of such a system?
I'm just experimenting a few different methods including this one for flying in a 100,100,7 map. If I'm suppose to do it quite differently, what should I read up on?
In response to Ash Abe Add
You wanna know about images, I think.

I took a minute to think about your experiment, and came up with this as my second solution:

var global
map_images[]


proc/register_map_image(image/image, visible_z_level)
if(!image || visible_z_level > world.maxz) return

if(!map_images)
map_images = list()
if(!map_images["[visible_z_level]"])
map_images["[visible_z_level]"] = list()
map_images["[visible_z_level]"] += image


mob/player
var
tmp/image/head
tmp/image/body
tmp/image/feet

New()
..()
head = new/image(icon = 'some_icon.dmi', loc = src, layer = src.layer)
body = new/image(icon = 'some_icon.dmi', loc = src, layer = src.layer)
feet = new/image(icon = 'some_icon.dmi', loc = src, layer = src.layer)

register_map_image(head, 3)
register_map_image(body, 2)
register_map_image(feet, 1)

// load the initial z level images (body)
on_map_entered(z)

Move(loc, dir, step_x = 0, step_y = 0)
// for whatever reason, if a player doesn't have a client...
if(!client) return ..()

var current_z = z
. = ..()
if(.)
if(z != current_z)
on_map_exited(current_z)
on_map_entered(z)

// if our new z level has images, load them.
proc/on_map_entered(z_level)
if(map_images && map_images["[z_level]"])
if(client)
client.images += map_images["[z_level]"]

// conversely, if the z level we are exiting has images,
// remove them.
proc/on_map_exited(z_level)
if(map_images && map_images["[z_level]"])
if(client)
client.images -= map_images["[z_level]"]


I'm not at my own terminal, so this code is not tested. I think it gets the idea across, though.

Maybe someone else with another, perhaps better, method of doing the same thing may chime in.
That looks awesome! It makes me think of the binding multiple icons on one z-level to make a big icon. Thanks for the idea! The question I have is will that take up a lot of space?
In response to Ash Abe Add
Ash Abe Add wrote:
That looks awesome! It makes me think of the binding multiple icons on one z-level to make a big icon. Thanks for the idea! The question I have is will that take up a lot of space?

"space" as in memory? I'm no expert, but that's not usually something you have to worry about.

However, a lot of objects in any scenario should be avoided. The more objects on a client's screen, the more overhead that's created (the slowdown can be vicious at times). So I'd suggest using single, large objects where applicable, as opposed to multiple, smaller objects.