ID:1591150
 
(See the best response by Jittai.)
Code:
mob/verb
CanSee()
if(!CanSee)
usr.CanSee=1
for(var/mob/M in view(6))
var/image/I = image('Base2.dmi',M)
usr << I

else
usr.CanSee=0
del(I)
del(I)


Problem description:

I'm trying to make it so that when users activate a certain skill or item, they can see a special effect. I figured I'd start small with images, and expand from there. I want them to be able to toggle the ability on and off, and not just activate it forever. Right now, all this does is stack a semitransparent overlay (Base2) every other time you click it, rather than delete the image. Is there a way to toggle the image on and off?
I would suggest creating and storing the image as a var. Then just add/subtract to/from client.images.
When trying to add it to/from client, nothing overlays onto the mobs. I put in an output to make sure that something wasn't locking up the verb, and the output places a message after each step for every step it makes it to, so it's definitely going through the steps. the only changes I made were I added
var/image/I = image('Base2.dmi') as a world var, then changed var/image/I = etc to client.images += I
I also tried M.client.images usr.client.images and src.client.images. Debug mode is on and I received zero errors.

Not sure what I'm doing wrong with that, but to reaffirm what my goal is, right now I'm essentially giving mobs a selectively visible aura. With the original programming, it added the image but would not remove it. There was a point where it would add the image to all the mobs, then subtract it from a single one while leaving the rest with an image. It was some variation of for(var/mob/M in view(6)) del(I), so I'm not sure why it was only deleting one instance, perhaps the one created most recently or something.
Best response
The reason your initial code didn't work was indenting issues. You refer to an I under the else but there is no I under that branch.

mob/var/image/I= null
mob/verb
CanSee()
if(!CanSee)
usr.CanSee=1

for(var/mob/M in view(6))
if(M.I==null)
M.I= image('Base2.dmi',M)
usr/client.images += M.I

else
usr.CanSee=0

for(var/mob/M in view(6))
usr/client.images -= M.I


I'm not sure what you're saying in your second post exactly - since what you're doing in your current code doesn't seem to line up.

Could you give a clearer example of what you want your code to be doing?
That actually does exactly what I need it to! Thank you very much :)
I did have to modify the if statement, as with the M.I==Null, it would only work the one time then it wouldn't work again. Moving everything to be right under the for makes it work exactly as I wanted it to. Thank you again for all your help :)
You can also create an image object and set its tag variable to something unique (Put the player's ckey in part of it, for example). You don't have to store it in a mob variable this way.

mob/proc/test()
var/image/i = image('icon.dmi',,"state")
i.tag = "[src.ckey]image"
src.client.images += i
mob/proc/test2()
src.client.images -= locate("[src.ckey]image")