ID:1853932
 
(See the best response by Kaiochao.)
Sorry if this has been answered, but I couldn't find answer anywhere, and I'm not even sure exactly how to word the the question.

Is there a way to label individual squares on the map in a way that can be referenced by the locate() proc?

I've been working on a card game, and I've been using a somewhat complicated algorithm to determine where a card needs to be placed, but I feel like my code would be a lot less cluttered if I could just label each space (ex. "Slot_1", "Slot_2", ... so on).

I would like to know the syntax for labeling an individual square and the syntax for referencing these squares.

Again, I'm not sure if I'm even asking the right question or going about this the right way.
The tag variable does exactly this.
Best response
In the map editor, right click a tile and hit Edit Instance. Then, set its "tag" variable to your label.

Calling locate(tag) will return that tile.
I knew it had to be something simple. Thanks!
One thing I forgot. How do I set a tile's tag using code?
In response to Yami Aguilar
If you have a reference to the tile, you can set its tag like any variable:
tile.tag = "blah blah"
I guess what I should be asking is how to reference the tile. That's something I haven't quite figured out how to do. Is it in the DM Reference?
Never mind. I just realized what I asked.
In response to Yami Aguilar
Unless you're instantiating the turf in code (i.e. new /turf/blah (some_location)), it should be accessible through the map editor.
Is there any way to return a value of (x,y,z) for a specific tile? I tried using src.loc, but it just returned "area."
src.loc is a reference to the tile that contains src.

If a turf exists on the map, it's location is always an area of sorts.

You could just do src.x, src.y, src.z.

But, what is the exact use case?
In response to Yami Aguilar
Yami Aguilar wrote:
Is there any way to return a value of (x,y,z) for a specific tile? I tried using src.loc, but it just returned "area."

var turf/tile = locate("Hey Now Mr. Brown Cow")
world << "([tile.x],[tile.y],[tile.z])"
In response to Super Saiyan X
That should be helpful enough. My exact use is to dynamically give each square a tag using a single proc when the game starts. I feel like that will be easier and more useful in the long run as opposed to doing it in the map edit screen.
In response to Pokemonred200
I find that slightly confusing. :/
In response to Yami Aguilar
For movable atoms (objs and mobs), loc can refer to any atom (area, turf, obj, mob). Movable atoms that are on the map (i.e. they have x, y, z coordinates) will have a turf as a loc. Movable atoms that are not on the map are either inside another movable atom (e.g. an item (obj) with a player (mob) loc) or in the void (loc == null).

However, turfs can only have an area loc. Turfs still have coordinates.

When you call locate(x, y, z), what you get is a turf with those coordinates.
In response to Kaiochao
I see. Thanks for your help. I now have enough information to work on my algorithm, and it is coming along quite nicely. :)
Would anybody mind critiquing me on my algorithm?

The goal is to assign the numbers 1-24 four times (once for each player) on a 16 x 16 grid. I'm going for a little something like this:

XXXX222222XXXX
XXXX222222XXXX
XXXX222222XXXX
XXXX222222XXXX
4444XXXXXX3333
4444XXXXXX3333
4444XXXXXX3333
4444XXXXXX3333
4444XXXXXX3333
4444XXXXXX3333
XXXX111111XXXX
XXXX111111XXXX
XXXX111111XXXX
XXXX111111XXXX

Mainly, I just want to know if this is sloppy looking and if there is a simpler or more effective way to achieve the same result. Here's my algorithm:

proc/assignTags()
var/S
for(var/KC as turf in world)
if(S==24)S=0
if((KC:x >= 5)&&(KC:x <= 10)&&(KC:y >= 1)&&(KC:y <= 4))
S++
KC:tag = "1KC[S]"
world << "[KC:x],[KC:y]--S=[KC:tag]" //included to make sure it works correctly
if((KC:x >= 5)&&(KC:x <= 10)&&(KC:y >= 11)&&(KC:y <= 14))
S++
KC:tag = "2KC[S]"
world << "[KC:x],[KC:y]--S=[KC:tag]"
if((KC:x >= 11)&&(KC:x <= 14)&&(KC:y >= 5)&&(KC:y <= 10))
S++
KC:tag = "3KC[S]"
world << "[KC:x],[KC:y]--S=[KC:tag]"
if((KC:x >= 1)&&(KC:x <= 4)&&(KC:y >= 5)&&(KC:y <= 10))
S++
KC:tag = "4KC[S]"
world << "[KC:x],[KC:y]--S=[KC:tag]"

If you are writing an algorithm that will affect a large number of turfs, then you will probably want to look at the block() proc. That should make things easier and more efficient than manually looping through the world or just using locate() alone.

Using block(), this should be about the same, functionally:
proc
assignTags()
var/S
var/list
turfs1 = block(locate(5,1,1), locate(10,4,world.maxz))
turfs2 = block(locate(5,11,1), locate(10,14,world.maxz))
turfs3 = block(locate(11,5,1), locate(14,10,world.maxz))
turfs4 = block(locate(1,5,1), locate(4,10,world.maxz))
if(S == 24) S = 0
for(var/turf/KC in turfs1)
S++
KC.tag = "1KC[S]"
for(var/turf/KC in turfs2)
S++
KC.tag = "2KC[S]"
for(var/turf/KC in turfs3)
S++
KC.tag = "3KC[S]"
for(var/turf/KC in turfs4)
S++
KC.tag = "4KC[S]"
Applying the (currently undocumented) "in" operator, defined as:
(n in a to b) == (a <= n && n <= b)


And also removing repetitive lines:
// These occur for every turf involved
S++
world << "[KC:x],[KC:y]--S=[KC:tag]"


And also properly casting your iteration variable KC as a turf:
for(var/KC as turf in world)
KC:x // the colon operator should be avoided

// becomes
for(var/turf/t)
t.x // the dot operator is safer


And also cleaning your conditionals:
if(A && B)
b stuff
if(A && C)
c stuff

// becomes
if(A)
if(B)
b stuff
else if(C)
c stuff


(and also applying some proper capitalization of stuff)

    proc/AssignTags()
var n
for(var/turf/t) if((t.x in 1 to 14) && (t.y in 1 to 14))
n = n % 24 + 1
if(t.x in 5 to 10)
if(t.y in 1 to 4)
t.tag = "1KC[n]"
else if(t.y in 11 to 14)
t.tag = "2KC[S]"
else if(t.y in 5 to 10)
if(t.x in 11 to 14)
t.tag = "3KC[S]"
else if(t.x in 1 to 4)
t.tag = "4KC[S]"
world << "([t.x], [t.y]), tag=[t.tag]" //included to make sure it works correctly


However, if you want your tiles numbered 1-24 for each player, instead of what it currently does, you're better off looping through each separate region separately.
    proc/AssignTags()
// This will go from 1 to 24.
var n

// This is a list of blocks. A block is a list of turfs.
var p = list(
block(locate( 5, 1, 1), locate(10, 4, world.maxz)),
block(locate( 5, 11, 1), locate(10, 14, world.maxz)),
block(locate(11, 5, 1), locate(14, 10, world.maxz)),
block(locate( 1, 5, 1), locate( 4, 10, world.maxz)))

// For every index in p (i.e. 1, 2, 3, 4)
for(var/i in 1 to p.len)
// Reset n to 0 to start counting for each region.
n = 0

// p[i] is the item in the list at the index i.
// In this case, p[i] is the i'th block.

// An example loop through the block to assign the tag.
// This goes in the order given by block().
// If you want to number your tiles in a specific order,
// then you can't use this exact loop.
for(var/turf/t in p[i])
t.tag = "[i]KC[++n]"
In response to Kaiochao
That isn't very modular. It would be better to just do something like this:
proc
tagblock(start, end, prefix, num = 1, suffix)
var/list/turfs = block(start, end)
. = num - 1
for(var/turf/t in turfs)
t.tag = "[prefix][++.][suffix]"
. = turfs

assignTags()
tagblock(locate(5,1,1), locate(10,4,world.maxz), "1KC")
tagblock(locate(5,11,1), locate(10,14,world.maxz), "2KC")
tagblock(locate(11,5,1), locate(14,10,world.maxz), "3KC")
tagblock(locate(1,5,1), locate(4,10,world.maxz), "4KC")
Page: 1 2