SCI1.1 Creating an Automatic Door
There is a door script included in the template, but so far I have not bothered to check it out. Instead, I create doors from scratch. Up to this point, I have only been making automatic doors that open when the ego gets anywhere near it.... I plan to go back through this and make it more flexible and even better, actually use the door script if possible, but for now, I just figured I would share and show how it is that I am throwing a lot of my doors together.
First thing I do, is create a local variable that I use to determine whether the door is open or not. I always assume at this point that the door is closed.
doorOpen = FALSE ; is the door open
doorBlocked = TRUE ; should the door block ego
doorDistance = 13 ; distance at which door should trigger
In the init section of my rooms script, I go ahead and add the statement which will initialise my door.
And now, the instance of the doorWay that holds all of the actual workings of the door.
(instance doorWay of Prop
(if (== gPreviousRoomNumber 53) ; depending on whether or not ego came from the other side
(= doorOpen TRUE) ; if so, mark it as open
(doorWay cel: (doorWay lastCel:)) ; and set it to the open cel
(doorBlocked ; if the door is blocking ego
(if (== (doorWay cel?) (doorWay lastCel:)) ; and it is on it's last cel
(= doorBlocked FALSE) ; mark it as unblocked
(doorWay ignoreActors: TRUE) ; and make the call to let ego pass
; the door is not blocking ego
((not (== (doorWay cel?) (doorWay lastCel:))) ; and it isn't on the last cel
(= doorBlocked TRUE) ; mark it as blocking ego
(doorWay ignoreActors: FALSE) ; and make the call to block ego
(doorOpen ; checks if the door is open
(if (> (gEgo distanceTo: doorWay) doorDistance)
(= doorOpen FALSE) ; mark the door as closed
(doorWay setCycle: BegLoop) ; and close door
; so if the door is closed
((< (gEgo distanceTo: doorWay) doorDistance)
(= doorOpen TRUE) ; marks the door as open
(doorWay setCycle: EndLoop)