ID:262086
 
Some reasont these little bit of code doesn't do I what I want it do. The proc doesn't seem to set the icon state. It remains at 13.

#define N   (istype(get_step(src, NORTH), src.type) || !get_step(src, NORTH))
#define NE (istype(get_step(src, NORTHEAST), src.type) || !get_step(src, NORTHEAST))
#define E (istype(get_step(src, EAST), src.type) || !get_step(src, EAST))
#define SE (istype(get_step(src, SOUTHEAST), src.type) || !get_step(src, SOUTHEAST))
#define S (istype(get_step(src, SOUTH), src.type) || !get_step(src, SOUTH))
#define SW (istype(get_step(src, SOUTHWEST), src.type) || !get_step(src, SOUTHWEST))
#define W (istype(get_step(src, WEST), src.type) || !get_step(src, WEST))
#define NW (istype(get_step(src, NORTHWEST), src.type) || !get_step(src, NORTHWEST))


obj/water
name = ""
icon = 'AnimatedWater.dmi'
MouseEntered(src) //here so I can test the state
usr << icon_state

New()
for(var/obj/water/T in range(src, 1))
T.Align()

proc/Align()
var/list/results[12]
results += TestA()
results += TestB()
results += TestC()
results += TestD()
results += Test1()
results += Test2()
results += Test3()
results += Test4()
results += Test5()
results += Test6()
results += Test7()
results += Test8()
for(var/result in results)
if(result)
src.icon_state = "[result]"
else
src.icon_state = "13"
return


proc/Test1() if(!N && E && S && !W) return 1
proc/Test2() if(!N && E && S && W) return 2
proc/Test3() if(!N && !E && S && W) return 3
proc/Test4() if(N && E && S && !W) return 4
proc/Test5() if(N && !E && S && W) return 5
proc/Test6() if(N && E && !S && !W) return 6
proc/Test7() if(N && E && !S && W) return 7
proc/Test8() if(N && !E && !S && W) return 8
proc/TestA() if(N && NE && E && !SE && S && SW && W && NW) return 9
proc/TestB() if(N && NE && E && SE && S && !SW && W && NW) return 10
proc/TestC() if(N && !NE && E && SE && S && SW && W && NW) return 11
proc/TestD() if(N && NE && E && SE && S && SW && W && !NW) return 12
What exactly did you want it to do, and what is it doing instead?

Did you realise you are going to have a list with 12 null elements then 12 numbers the way you have results set up? results[12] should make a list of 12 elements, each being null, then you go and add numbers which should be tacked on after them.

When your loop goes through the results and changes the icon state, it is going to completely reset it when it finds the next match. Is that what you wanted, or did you mean to append it to the icon state? It does not appear as though it would work whatever it is for, as it will set the icon state to "13" if the if statement in test8 evaluates to true, and "12" if it does not, regardless of what the other functions return. Perhaps you want a break in there.
Ryne Rekab wrote:
Some reasont these little bit of code doesn't do I what I want it do. The proc doesn't seem to set the icon state. It remains at 13.

This is Foomer's 13 state auto-joining code. I think the #define code is screwing with it, somehow. Well, at least it did with my own version in Chatters. I ended up rewriting a bit of it to use a proc instead of #define. Try this out instead:

atom
proc/Align()
var/list/results = list()
results += TestA()
results += TestB()
results += TestC()
results += TestD()
results += Test1()
results += Test2()
results += Test3()
results += Test4()
results += Test5()
results += Test6()
results += Test7()
results += Test8()
for(var/result in results)
if(result)
src.icon_state = "[result]"
return
src.icon_state = "13"
return

proc/is_type(var/dir)
if(isturf(src))
if((istype(get_step(src, dir), src.type)) || (!get_step(src, dir))) return 1
else if(isobj(src))
if(!get_step(src, dir)) return 1
for(var/obj/O in get_step(src, dir))
if(istype(O, src.type))
return 1
else return 0

proc/TestA() if(is_type(NORTH) && is_type(NORTHEAST) && is_type(EAST) && !is_type(SOUTHEAST) && is_type(SOUTH) && is_type(SOUTHWEST) && is_type(WEST) && is_type(NORTHWEST)) return 9
proc/TestB() if(is_type(NORTH) && is_type(NORTHEAST) && is_type(EAST) && is_type(SOUTHEAST) && is_type(SOUTH) && !is_type(SOUTHWEST) && is_type(WEST) && is_type(NORTHWEST)) return 10
proc/TestC() if(is_type(NORTH) && !is_type(NORTHEAST) && is_type(EAST) && is_type(SOUTHEAST) && is_type(SOUTH) && is_type(SOUTHWEST) && is_type(WEST) && is_type(NORTHWEST)) return 11
proc/TestD() if(is_type(NORTH) && is_type(NORTHEAST) && is_type(EAST) && is_type(SOUTHEAST) && is_type(SOUTH) && is_type(SOUTHWEST) && is_type(WEST) && !is_type(NORTHWEST)) return 12
proc/Test1() if(!is_type(NORTH) && is_type(EAST) && is_type(SOUTH) && !is_type(WEST)) return 1
proc/Test2() if(!is_type(NORTH) && is_type(EAST) && is_type(SOUTH) && is_type(WEST)) return 2
proc/Test3() if(!is_type(NORTH) && !is_type(EAST) && is_type(SOUTH) && is_type(WEST)) return 3
proc/Test4() if(is_type(NORTH) && is_type(EAST) && is_type(SOUTH) && !is_type(WEST)) return 4
proc/Test5() if(is_type(NORTH) && !is_type(EAST) && is_type(SOUTH) && is_type(WEST)) return 5
proc/Test6() if(is_type(NORTH) && is_type(EAST) && !is_type(SOUTH) && !is_type(WEST)) return 6
proc/Test7() if(is_type(NORTH) && is_type(EAST) && !is_type(SOUTH) && is_type(WEST)) return 7
proc/Test8() if(is_type(NORTH) && !is_type(EAST) && !is_type(SOUTH) && is_type(WEST)) return 8


~X
In response to Xooxer
Hey thanks Xooxer I am going to try this out. I am trying to get my water like Chatters believe it not =P. I need to make 12 icon state tho, boring =P!
In response to Ryne Rekab
Werid, I used what you gave me, but now it doesn't seem to set the icon_state variable...
In response to Ryne Rekab
Oh, I see the problem now:

obj/water
name = ""
icon = 'AnimatedWater.dmi'
MouseEntered(src) //here so I can test the state
usr << icon_state

New()
for(var/obj/water/T in range(1, src))
T.Align()


You had the arguments to the range() proc backwards. The distance comes first followed by the reference.

~X
In response to Xooxer
Thanks Xoox, I forgot to make the objs use align(). Now I have to go make all of those icons XD
In response to Xooxer
Heh, as a side note, if anyone'd care to rewrite it to make it more pleasant to look at or more efficient, be my guest. I mostly only posted it to remind myself that it was possible. :P
In response to Foomer
Oh, yea... sure you did =P