Page 1 of 1

Trapdoor Hallway.

Posted: Sat Nov 24, 2012 12:19 am
by Chuck_ChuckRazool
I'm trying to put in a classic sort of trap door feature where there's a single width hallway with a bunch of trap doors. They open one by one in sequence and reset themselves all at once. The player has to wait for them to be all closed and then dash forward with the doors opening up behind them. Classic dungeon stuff and it also cuts the player off from the previous area because it's impossible to go in reverse without falling in a pit.

I'm having a hard time figuring out the scripting though. The reset is easy enough just connect a timer to a script entity so it activates this script every five or so seconds.
function halltrap()
if halltrap1:isOpen() and
halltrap2:isOpen() and
halltrap3:isOpen then
halltrapreset:activate()
end
end
Halltrapreset would probably be a hidden pressure plate that closes all the trap doors. The opening of the doors would be on increasing timers 1;2;3;etc. what I can't quite figure out is how keep them from getting out of sequence. I was thinking of maybe doing a second timed script that checks the doors every half second and deactivates the door timers if the door is open. It's also possible that I'm going about this completely wrong, I think that script would look like this
function halltraprun()
if halltrap1:isOpen() then
halltimer1:deactivate()
else
halltimer1:activate()
end
end
Also is there a way to make that one script check all of the traps or would I need a separate one for each? I have no scripting experience all I know is what I've read in the script reference page and from watching those komag youtube videos.

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 12:46 am
by J. Trudel
Link this function to a single timer and it should do the trick. Make sure you trapdoors are named as trapdoor1 ... trapdoor2 etc etc
SpoilerShow

Code: Select all

count = 0
function traphall()
  if count == 1 then
    trapdoor1:open()
  elseif count == 2 then
    trapdoor2:open()
  elseif count == 3 then
    trapdoor3:open()
  elseif count == 4 then
    trapdoor1:close()
    trapdoor2:close()
    trapdoor3:close()
    count = 0
    return
end
  count = count + 1
end

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 3:18 am
by Komag
Yes, do that, and set the timer to maybe 1 second or 1.5 seconds.

(except keep the name of the counter the same, such as this:

Code: Select all

trapCount = 0
function trapHall()
  if trapCount == 1 then
    trapDoor1:open()
  elseif trapCount == 2 then
    trapDoor2:open()
  elseif trapCount == 3 then
    trapDoor3:open()
  elseif trapCount == 4 then
    trapDoor1:close()
    trapDoor2:close()
    trapDoor3:close()
    trapCount = 0
    return
  end
  trapCount = trapCount + 1
end

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 3:59 am
by J. Trudel
Thanks for noticing my error Komag, it's corrected.

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 8:02 am
by Chuck_ChuckRazool
Thanks alot guys. Worked like a charm. 1.5 seconds is super slow though. I set it to .75

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 11:55 am
by Komag
Okay, whatever feels good to you, but keep in mind that many players on older hardware will have a harder time moving fast enough, so it's good to test it on a weaker computer if you can, or have a friend try it who has a weak laptop, etc.

Re: Trapdoor Hallway.

Posted: Sat Nov 24, 2012 2:17 pm
by Neikun
I'm fairly certain that without thunderstuck, you can't walk over a pit successfully if it toggling faster than one second. If that.