ID:142049
 
Code:
proc/animationnormal(message,map,character,object,first,second,closeup)
var/tempx = 0 // This is only in case the character is on the right side of the room- it'll move the area it searches over to the right. Could be made simpler...
if(object=="prosecution") tempx = 33
if(closeup) // Is this one of the special close-up animations? If so, activate the spiffy background behind the animation.
for(var/x=1, x<=8, x++) // All animations are 8x6 tiles.
for(var/y=1, y<=6, y++)
for(var/obj/Z as obj in world) if(istype(Z,/obj/closeup)&&Z.room==map&&Z.x==(x+tempx)&&Z.y==y) Z.icon_state = "closeup [x-1],[y-1]"
for(var/x=1, x<=8, x++) // Activate the talking version of this animation.
for(var/y=1, y<=6, y++)
for(var/obj/Z as obj in world) if(Z.room==map&&Z.x==(x+tempx)&&Z.y==y)
if(istype(Z,/obj/defense||/obj/prosecution||/obj/judge||/obj/aide||/obj/witness)) Z.icon_state = "[first] [x-1],[y-1]" // Large icons start at "[icon_state name] 0,0", so we need to take one off of both x and y.
display(message,map,character) // Displays text on the screen.
for(var/x=1, x<=8, x++) // Activate the non-talking version of this animation.
for(var/y=1, y<=6, y++)
for(var/obj/Z as obj in world) if(Z.room==map&&Z.x==(x+tempx)&&Z.y==y)
if(istype(Z,/obj/defense||/obj/prosecution||/obj/judge||/obj/aide||/obj/witness)) Z.icon_state = "[second] [x-1],[y-1]"


Problem description:

This code is the only code in my project that affects the icon_state of the characters.

What ends up happening, however, is that some icon_states end up becoming invisible to people. One person will be able to see a character, while another can't. Which icon_states any particular person might be able to see seems completely random.

I ended up putting a snippet of code into my project so that I could check variables at runtime. When I right-clicked on an invisible character, the icon preview showed a visible icon, as if the internal invisible variable had been turned on... but my var checker turned up nothing out of the ordinary.

I'm thinking this might actually be a problem with the BYOND code itself... Given that this proc is from my first from-scratch project, it probably should be able to be rewritten to be much more efficient- and it just might end up solving my problem. If there's no problem with the way the code itself is written, could someone more experienced show me how to make it more efficient?

Thanks in advance!

----------Edit----------

To clarify- this code is called when a player inputs a message. The player's character switches to a "talking" version of the chosen animation while the text is displayed on the screen, and, once done, goes to the "normal" animation version.
Alrighty, what is the code meant to do, and when?
In response to Stephen001
The code is called when a player inputs a message. The player's character switches to a "talking" version of the chosen animation while the message is displayed on the screen, and, once done, goes to the "normal" version.