ID:1506784
 
(See the best response by Koshigia.)
Problem description: I'm not really sure if this is the right place to put this, but I couldn't really think of anywhere else.

I struggle sometimes at understanding things, if I'm honest, I have to re-read certain subjects/topics multiple times, but I try.

So I was reading the part about turf borders and I wanted your opinion on whether or not you believe I've interpreted it correctly, using the comments I added on the code.

turf
starting_line
density = 1
icon_state = "starting-line"

New()
..()

if(density)
var/n = 0
var/turf/t

t = locate(x, y + 1, z)
if(t && t.density) n += 1 //these set of numbers are used because there is only one way to make 15. By adding them all together.
t = locate(x + 1, y, z) //if we were to double these amounts to make n < 30. The icons states would need to be changed also. lowest possible number to highest.
if(t && t.density) n += 2
t = locate(x, y - 1, z)
if(t) //for shadows
if(t.density)
n += 4

else //if there is no dense turf in y - 1,
t.overlays += icon('outline.dmi', "shadow") //add the shadow

t = locate(x - 1, y, z)
if(t && t.density) n += 8

if(n < 15)
overlays += icon('outline.dmi', "[n]") //n = icon_state


Best response
Maybe I'm tired, but the only thing that strikes me as weird is the if(n <15). Is this a sanity check, because according to the code I see n will never be greater than 15?

To answer your question, it also appears as if you got the hang of what this code does. Pay particular attention to the n variable. The reason these numbers are used are because you can "take them off" in reverse order from largest to smallest and know what directions contributed to the total value.

For instance, if n = 14. You know it is made of the individual components of 8, 4, and 2; corresponding to WEST, SOUTH, and EAST.

You'll have to ask one of the more knowledgeable persons about the technical term for this useage of variables, but I know this use of variables was common in MUDs. It seems to be a more efficient way of storing similar, but separate information. In this example, you have one variable effectively capable of storing information about 4 independent directions.
It's less than 15 because all the numbers added together = 15. Doesn't matter if it's more, so you could us if(n <= 14) and I believe it would work the same.
Ah-yep. I knew I was being silly... Ah-well, no shame in admitting imperfection. Only means you're wise enough to seek improvement! =)
In response to Koshigia
Koshigia wrote:
Ah-yep. I knew I was being silly... Ah-well, no shame in admitting imperfection. Only means you're wise enough to seek improvement! =)

Very true. To be honest, I felt a little silly posting this topic since it was a tutorial. But hey if you don't get something you got to ask.