ID:138379
 
How did you achieve the opening of the doors effect in SpaceTug?

Here's my code, for a game I previously was going to integrate into CATs, but then thought against it:

mob
Bump(O)
O:Bumped()

obj
terran
doors
icon = 'terran_doors.dmi'
icon_state = "closed"
density = 1
opacity = 1
touch_sensitive
proc
Bumped()
src.density = 0
src.opacity = 0
src.icon_state = "open"
flick("opening",src)
usr.loc = src.loc
spawn(30) Close()
Close()
var/mob/M
var/i
for(M in view(0,src))
i++
break
if(i)
spawn(30) Close()
return
else
src.density = 1
src.opacity = 1
src.icon_state = "closed"
flick("closing",src)

It doesn't work, though. It just immediately blinks to "closed" or "open" without bothering to flick the "closing" or "opening" states.

So... how'd you do it?
src.icon_state = "closed"
flick("closing",src)

It doesn't work, though. It just immediately blinks to "closed" or "open" without bothering to flick the "closing" or "opening" states.

So... how'd you do it?

It looks like the difference is I set the icon_state after I started the flick. (Which makes sense, because depending on how Dantom implemented it, otherwise the door could appear to flicker closed before it flicked closing.)

verb/close()
set category = "door"
set src = oview(1)
if(!density)
view(src) << 'door1.wav'
flick("closing", src)
icon_state = "closed"
density = 1
opacity = initial(opacity)
cost = initial(cost)
DisableVacuum()
In response to Guy T.
[edited: added comments]

[edited again: added small thesis]

It looks like the difference is I set the icon_state after I started the flick. (Which makes sense, because depending on how Dantom implemented it, otherwise the door could appear to flicker closed before it flicked closing.)

verb/close()
set category = "door"
set src = oview(1)
if(!density)
view(src) << 'door1.wav'
flick("closing", src)
icon_state = "closed"
density = 1
opacity = initial(opacity)
cost = initial(cost)
DisableVacuum()

Okay, here's the changed code, and it still blinks to "closed" without displaying the "closing" state.

obj
terran
doors
icon = 'terran_doors.dmi'
icon_state = "closed"
density = 1
opacity = 1
touch_sensitive
proc
Bumped() //when a touch sensitive door is bumped, it opens
src.density = 0
src.opacity = 0
flick("opening",src)
src.icon_state = "open"
spawn(30) Close()
Close() //after 3 seconds, it closes again
var/mob/M
var/i
for(M in view(0,src))
i++
break
if(i) //if there is a mob in the way, wait another three seconds
spawn(30) Close()
return
else //there isn't a mob in the way
src.density = 1
src.opacity = 1
flick("closing",src)
src.icon_state = "closed"

Perhaps the spawn(30) in there is causing flick() to fail? It wouldn't explain why the "opening" state wouldn't be displayed, but if the spawn() were messing up the other flick(), it would explain why the "closing" state wouldn't be displayed.
In response to Spuzzum
On 9/18/00 8:30 pm Spuzzum wrote:

Perhaps the spawn(30) in there is causing flick() to fail? It wouldn't explain why the "opening" state wouldn't be displayed, but if the spawn() were messing up the other flick(), it would explain why the "closing" state wouldn't be displayed.

What happens when you remove the spawn()? That might help diagnose the problem.
In response to Tom H.
On 9/20/00 4:52 pm Tom H. wrote:
On 9/18/00 8:30 pm Spuzzum wrote:

Perhaps the spawn(30) in there is causing flick() to fail? It wouldn't explain why the "opening" state wouldn't be displayed, but if the spawn() were messing up the other flick(), it would explain why the "closing" state wouldn't be displayed.

What happens when you remove the spawn()? That might help diagnose the problem.

Not sure, because if I did that, my door wouldn't work. =)

Will test.

[1 minute later]

Nope. Still doesn't work. Scratch that idea. Any thoughts on what might be causing it?
In response to Spuzzum

It is not supposed to matter in which order you set the icon state and call flick(), since the client doesn't get a map refresh until the end of the server tick anyway.

If I can't reproduce this, would you mind sending me the code snippet and icon files? Are you sure your icon has the "closing" and "opening" states defined? (Sorry, but I can't help asking, just in case!)

--Dan
In response to Dan
It is not supposed to matter in which order you set the icon state and call flick(), since the client doesn't get a map refresh until the end of the server tick anyway.

If I can't reproduce this, would you mind sending me the code snippet and icon files? Are you sure your icon has the "closing" and "opening" states defined? (Sorry, but I can't help asking, just in case!)

Yep, I'm pretty certain that the "closing" and "opening" states are defined. You shame me, Dan. =)

I'll try and test it in another environment, and see if it occurs there. Then I'll get back to you.
In response to Spuzzum
I'll try and test it in another environment, and see if it occurs there. Then I'll get back to you.

Okay. In another environment, and still no cigar. Note that my icons are directional movies... might that have any effect?

Anyway, you can download the EXTREMELY basic demo here.

flick() is acting up on me!
In response to Spuzzum
Ah. The problem is even simpler than expected: flick() doesn't work on obj types. There must be some legacy reason for that, but no doubt it will be fixed in the next release. Guy T. must have been using turfs for his doors.

Thanks for the find!