ID:262518
 
Code:
turf
wall
density=1
icon='wall.dmi'
proc/Update()
var/state=0
for(var/turf/wall/W in get_step(src,NORTH))
if(W)
state+=1 //wasn't sure if the constants would give the right icon states.
break
for(var/turf/wall/W in get_step(src,SOUTH))
if(W)
state+=2
break
for(var/turf/wall/W in get_step(src,WEST))
if(W)
state+=4
break
for(var/turf/wall/W in get_step(src,EAST))
if(W)
state+=8
break
src.icon_state="[state]"
New()
..()
for(var/turf/wall/W in view(1))
W.Update()


Problem description: The problem, short and simple, the icon states don't change.
When you use "for(var/turf/wall/W in get_step(src, NORTH)", think of what you are actually trying to achieve.

Simply, you are trying to search for turfs in the contents of another turfs, and we know that's not possible. Only one turf is able to be in one tile. So basically "state" will never budge. Also, the if(W) statement is not needed.

Here's an example of what could simulate what you are trying to do:

turf/wall
proc/Update()
var/state = 0
if(istype(get_step(src, NORTH), /turf/wall)) state += 1
// get_step() returns a turf, so we just check if the turf is that wall we want.
if(istype(get_step(src, SOUTH), /turf/wall)) state += 2
// etc


Or to make it more efficient for your own needs, you could do this.

turf/wall
proc/Update()
var/state = 0
for(var/i in list(1,2,4,8))
if(istype(get_step(src,i),/turf/wall)) state+=i
src.icon_state="[state]"


~~> Dragon Lord
In response to Unknown Person
Thanks that helped and worked. I just need help now when I destroy a wall. I had a slight problem before because I updated the surrounding walls before I deleted "dead" wall. However, I fixed that by creating a sort of place holder so it could be deleted but the surrounding walls would still be updated.

Here's my code
turf
wall
Del()
var/area/L=src.loc
..()
for(var/turf/wall/W in oview(L,1))
W.Update()


I also tried using an obj, but that didn't work either. Any help is appreciated. Thank you.

[EDIT] The weirdest part is, it updates pretty much all the other turfs in the world except the surrounding ones.
In response to Dark Weasel
turf
wall
Del()
var/area/L=src.loc
..()// It is being deleted here... Therefore the rest of the proc isn't being executed...
for(var/turf/wall/W in oview(L,1))
W.Update()
In response to Hiddeknight
Then I don't know what to do for that.

I can't think of a way to get it to work.
In response to Dark Weasel
Try this:

turf/wall
Del()
for(var/turf/wall/W in oview(src,1))
W.Update(src)
..()

proc/Update(turf/Ignore)
var/state = 0
for(var/i in list(1,2,4,8))
var/turf/T = get_step(src,i)
if(T == Ignore) continue
if(istype(T,/turf/wall)) state+=i
src.icon_state="[state]"


~X
I've written a pretty thorough article on autojoining walls that should help you out:

Dream Tutor: All Together Now

You should also check out Pmikell's page on the subject, linked from that article.

Lummox JR
In response to Lummox JR
Thanks Lummox and Xooxer.