ID:146493
 
Code:
            showgrid()
for(var/area/A in world)
if(!A.icon)
A.icon = 'cursor.dmi'
A.icon_state = "grid"
A.layer = 5
else
A.icon = null
A.icon_state = null
A.layer = 1


Problem description:

Bear with me, I'm kind of still newbish to coding. What I'm trying to do is create a grid:
Grid on black turf:http://img272.echo.cx/img272/9197/gridonblack3io.png
Grid on Dragon Warrior 4 grass turf:http://img200.echo.cx/img200/863/gridongrass3qc.png
Grid disabled on grass turf:http://img256.echo.cx/img256/2784/nogridongrass8ao.png

Ignore the sidebar.

The little square that's different is a cursor.

The problem I'm having is that even though the grid itself works fine, it's showing to everyone when I only want it to show to the user who specified it to be on. For the rest of the users, it should be off unless they click on the verb to turn on the grid.

I've tried searching the forums and the resources on BYOND if there was anything about making grids but unfortunately, I haven't been able to find anything. I've also tried a method of making an area for the grid, painting the map with it, and using invisible/see_invisible but that method didn't work. If anyone wants, I can post the coding I used in the other method, although since the above code seems to work better, that's the one I'm trying to work upon.
Using invisibility/see_invisible sounds like a good approach. What exactly wasn't working about it?

You could use image objects (look up "image objects" in the DM reference); though it's slight overkill when you could use invisibility.
In response to Crispy
First I added in this to the end, where all of the areas are:
area
grid
icon = 'cursor.dmi'
icon_state = "grid"
layer = MOB_LAYER + 1
invisibility = 1

Then I added this to user that logs in.
    var/see_invisible = 0

Although it gave the error: "testRPG.dm:250:error:see_invisible :duplicate definition (conflicts with built-in variable)"
so I just deleted the variable from the mob/user.

After that, I added in a verb for the user to toggle it.
        ShowGrid()
if(src.see_invisible == 0)
src.see_invisible = 1
else
src.see_invisible = 0


And lastly, I painted the map with the grid area. Although whenever I try to toggle it, it didn't work. I tried making it just
area
icon = 'cursor.dmi'
icon_state = "grid"
invisibility = 1
layer = MOB_LAYER + 1


which worked, but it screwed around with the weather system, which uses a similar version of
                for(var/area/A in world)
if(!A.icon)
A.icon = 'weather.dmi'
A.icon_state = "rain"
A.layer = 5
A.invisibility = 0
else
A.icon = null
A.icon_state = null
A.layer = 1


Also, thanks for pointing me towards image objects, although now my only problem is that I don't know how to apply it to an area so that I can toggle it.


In response to Blazor07
You don't need to define the see_invisible var; it's built-in.

As for the grid not showing up, the /area/grid is an object, so you need to place it on your map. (On every tile of the map, in fact.)

But from the way your weather system is set up it looks like that will conflict as well, so you'll probably have to go with images.

Probably the most efficient way of doing this is to give each /area object its own image object for the grid, and keep a global list of all grid images:

var/list/all_grid_images = list()

area
var/image/grid_image = null
New()
..()
all_grid_images += grid_image
grid_image = image('grid.dmi',src)
Del()
// These two lines are not necessary, but speed up deletion
all_grid_images -= grid_image
del grid_image
..()


Note that by default there is only one /area object per /area subtype, so you won't get one image object per tile (which would be extremely wasteful).

Now, when you want to toggle the grid, add/subtract all of the images in all_grid_images from the player's client's images var. I'll leave this as an exercise for you, as you seem capable. =)
In response to Crispy
All right, I've tried it and although it gives me no errors when I compile it, and I can see that area/grid shows up as the grid I want it to in the .dmp, I might have botched up on the toggle. Whenever I use it in-game, it does nothing except give the output '/list'.
        ToggleGrid()
if (usr.client.images == null)
usr.client.images = all_grid_images
usr.client << usr.client.images
else
usr.client.images = null
usr << usr.client.images


And just for reference:

var
list
all_grid_images = list()

area/grid
var
image
grid_image = null
New()
..()
all_grid_images += grid_image
grid_image = image('cursor.dmi',src,"grid")
Del()
all_grid_images -= grid_image
del grid_image
..()
icon = 'cursor.dmi'
icon_state = "grid"


Hrm, I'm pretty much a newbie at this still and tried looking up references. From what it seems, it should work but it isn't.

(First time using image objects too. >_<;;)

[Edit]
Nevermind, got it working, thanks.
[/Edit]