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.
1
2
May 17 2015, 11:48 am
|
|
The tag variable does exactly this.
|
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. |
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?
|
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") |
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() |
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 |
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 And also properly casting your iteration variable KC as a turf: for(var/KC as turf in world) And also cleaning your conditionals: if(A && B) (and also applying some proper capitalization of stuff) proc/AssignTags() 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() |
In response to Kaiochao
|
|
That isn't very modular. It would be better to just do something like this:
proc |
1
2