ID:142911
 
Code:
        doors_closed_front_inside1
icon = 'closed urahara shop doors.dmi'
icon_state = "1"
name = "door closed"
layer = MOB_LAYER+2
density = 1
proc/open1()
if(usr.loc == locate(4,7,1))
icon_state = "13"
density = 0
else
icon_state = "1"


ok so im trying to make it so that when a usr stands in front of the door it plays an animation of it opening(icon_state = "13")and turn its density to 0. Compiling shows no problems BUT when I try it it doesn't work any help?( i have thought maybe that its cause the if and else is only done once and i need to make it into a loop but how?)

You're never calling the proc, usr is improper to be using in procs, and what you've got there is simply going to be a major headache to actually work with. You need to take a more object-oriented approach. Here's a simple door that will open and close as you move on and off of it:

turf
door
icon = 'door.dmi'
icon_state = "closed"
Entered()
flick("opening",src)
icon_state = "open"
Exited()
flick("closing",src)
icon_state = "closed"


Notice that there's no need for density. What's the point? You're opening it whenever somebody walks up to it anyway. Now, let's change this a bit to use variables, so we can easily define different types of doors:

turf
door
icon = 'door.dmi'
icon_state = "closed"
var/closedstate = "closed"
var/openstate = "open"
var/closingstate = "closing"
var/openingstate = "opening"
Entered()
flick(openingstate,src)
icon_state = openstate
Exited()
flick(closingstate,src)
icon_state = closedstate

yourdoor
icon_state = "1"
closedstate = "1"
openstate = "?"
closingstate = "?"
openingstate = "13"


See how much easier it is when all you need to do is type in five variables to make a door?
In response to Garthor
ty ill try that and see what happens i thought about flick but since i never really used it before, I thought flick just flashes the animation
In response to Garthor
oh about the density part that is because the door is on a wall beacause I made it so the person has to walk thorught he wall
In response to StevieMan
    doors_closed_front_inside1
icon = 'closed urahara shop doors.dmi'
icon_state = "closed"
layer = MOB_LAYER+2
var/closedstate = "closed"
var/openstate = "open"
var/closingstate = "closing"
var/openingstate = "opening"
Entered()
flick(openingstate,src)
Enter
icon_state = openstate
while(usr.loc == locate(4,8,1))
sleep(1)
goto Enter
flick(closingstate,src)
icon_state = closedstate
door
icon_state = "1"
closedstate = "1"
openstate = "17"
closingstate = "15"
openingstate = "13"


ok so the eixted would work. It would show the closing animation even if the character was in the vicinity of the door so i added the while and goto to make it so it keeps the state at opened until the usr leaves the vacinity of the door. first i tried it without the sleep but like it lagged like hell so i added it
In response to StevieMan
I have no clue what you just said and what you did to what I posted is a complete and utter butchery of what I wrote. Why'd you have to go and do that? What do you have against Exited()? And that's aside from you completely butchering the nice, simple, object-oriented design I wrote for you. Oh, and hey, you used usr in Entered(), the exact thing I told you NOT TO DO.
turf/door
icon='door.dmi'
density=1

turf/trigger
icon='trigger.dmi'
Entered()
for(var/turf/T in oview(1))
if(istype(T,/turf/door))
flick("opening",T)
T.icon_state="open"
T.density=0

So basically, slap the trigger down on the map in front of the door and when you step on the trigger the door opens. I think this is more what you were looking for..

Now what do you say?
In response to ErdricktheGreat
For the MILLIONTH GODDAMN TIME, don't use usr in procs. ESPECIALLY movement procs. Change oview(1) to oview(src,1)
In response to Garthor
wow ur scary but umm what i meant was the exited wouldn't work so I replaced it with while. I really still don't get why you shouldn't be using usr in procs it seemingly works with no problems...?

also I don't like triggers very much I have thought of them but said nah... too cluttered
In response to StevieMan
Because using usr in procs seemingly works fine. What people use usr for is "whatever I am thinking of at this very moment." So, naturally, they misuse it and then it seems to work fine up until the very moment where it doesn't, and that moment happens to be over a month down the line when you've already forgotten about your use of usr and something completely different is causing errors you can't track down because you misused usr.

http://www.byond.com/members/ DreamMakers?command=view_post&post=35932

Now, why the hell didn't Exited() work? Because what you did is a million times worse, and when I tried what I wrote it worked perfectly fine.
In response to Garthor
o i see thx but umm the exited made it so the door showed closing animation while the usr was in the contents of the door. So i changed it once again
while(M in src.content)
I'm not sure I know a way to use it without a usr in there.

The code is now:
turf
doors_closed_front_inside1
icon = 'closed urahara shop doors.dmi'
icon_state = "closed"
layer = MOB_LAYER+2
var/closedstate = "closed"
var/openstate = "open"
var/closingstate = "closing"
var/openingstate = "opening"
Entered(Z)
flick(openingstate,src)
Enter
var/mob/M = Z
icon_state = openstate
while(M in src.contents)
sleep(1)
goto Enter
flick(closingstate,src)
icon_state = closedstate
door
icon_state = "1"
closedstate = "1"
openstate = "17"
closingstate = "15"
openingstate = "13"


side note:I changed it to in src.contents because I'm going t use the door in other places not just at 4,8,1

side note2:seriously they should change the forums I don't like having to click show all all the time
In response to Garthor
Hmm, surprised I missed that. Thanks for catching that Garthor. But....

oview proc

Format:
oview(Dist,Center=usr)

Returns:
A list of visible objects within Dist tiles of Center, excluding Center.

Args:
Dist: A number.
Center: An object on the map.
This instruction is just like view() except it doesn't include Center or its contents in the list.

Example:
oview() << "to others in sight of [usr]"

So, shouldn't it be oview(1,src) according to the format Garthor?

In response to ErdricktheGreat
Both oview(src,1) and oview(1,src) work.
In response to StevieMan
The appropriate thing to use would be the argument to Entered(). However, if the door is closing while something is in it, try this instead:

turf/door
Entered()
if(contents.len == 1)
flick(openingstate,src)
icon_state = openstate
Exited()
if(contents.len == 0)
flick(closingstate,src)
icon_state = closedstate


Obviously, anything at all will jam a door open. Watch out for butterflies during elephant attacks.
In response to Garthor
Well, regarding me using usr in the procedure, I didn't realize the default object defined in oview() was usr until now. I guess that mistake isn't as bad as actually writing usr in.
In response to ErdricktheGreat
o i c what you did you changed it to see if theres contents in there smart
In response to Garthor
2 things:

1. are you sure that code will work if there are MULTIPLE people in the doorway(yes i plan to do that)

2. If it was a double door system(2 sliding doors) and I wanted it to be that if one of the doors opened so did the second door(the one next to it) how would that work?
In response to StevieMan
turf/door/multiple
var/range = 1
Entered()
var/len = contents.len
var/list/adjacent = list(src)
for(var/turf/door/multiple/D in orange(src,range))
len += D.contents.len
adjacent += D
if(len == 1)
for(var/turf/door/D in adjacent)
flick(D.openingstate,D)
D.icon_state = D.openstate
Exited()
var/len = contents.len
var/list/adjacent = list(src)
for(var/turf/door/multiple/D in orange(src,range))
len += D.contents.len
adjacent += D
if(len == 0)
for(var/turf/door/D in adjacent)
flick(D.openingstate,D)
D.icon_state = D.closedstate
In response to Garthor
O thank you I wasn't thinking of completely rearranging everything and using in adjacent you're like pro at this
In response to StevieMan

sorry for bumping this back up but I've been away. Now it's 4 doors 2 in each tile and I need help coding it without using a trigger. I already made one using a trigger:
obj
var/closedstate = "closed"
var/openstate = "open"
var/closingstate = "closing"
var/openingstate = "opening"
front_doors
icon = 'Closed Urahara Shop Doors.dmi'
name = "sliding doors"
layer = MOB_LAYER+2
var/range = 1
front1
icon_state = "f1.closed"
closedstate = "f1.closed"
openstate = "f1.opened"
closingstate = "f1.closing"
openingstate = "f1.opening"
front2
icon_state = "f2.closed"
closedstate = "f2.closed"
openstate = "f2.opened"
closingstate = "f2.closing"
openingstate = "f2.opening"
back1
icon_state = "b1.closed"
closedstate = "b1.closed"
openstate = "b1.opened"
closingstate = "b1.closing"
openingstate = "b1.opening"
back2
icon_state = "b2.closed"
closedstate = "b2.closed"
openstate = "b2.opened"
closingstate = "b2.closing"
openingstate = "b2.opening"
turf
trigger
Entered(Z)
var/mob/M = Z
if(M in contents)
for(var/obj/front_doors/D in orange(1,src))
flick(D.openingstate,D)
D.icon_state = D.openstate
for(var/obj/front_doors/D in contents)
flick(D.openingstate,D)
D.icon_state = D.openstate
Exited(Z)
var/mob/M = Z
Enter
while(M in contents)
sleep(1)
goto Enter
for(var/obj/front_doors/D in orange(1,src))
flick(D.closingstate,D)
D.icon_state = D.closedstate
for(var/obj/front_doors/D in contents)
flick(D.closingstate,D)
D.icon_state = D.closedstate


I don't like triggers so any ideas from proness garthor? picture of 4 doors with 2 in each tile(marked 1 and 2) shown below


Image Hosted by ImageShack.us