Page 1 of 1

trap door sequence

Posted: Thu Sep 20, 2012 1:06 pm
by papazombie
I need help to create a sequence of trapdoors so that only one is open at a time and the group has to jump at a time to avoid falling rapidly. I've tried and I canĀ“t do it using timers :(
thanks again :D

Re: trap door sequence

Posted: Thu Sep 20, 2012 1:11 pm
by Grimwold
The following post by Antti may help with what you are trying to do

viewtopic.php?f=14&t=3213&hilit=tick

He describes using a timer that calls a function every interval and depending on the value it does something different... could be used to create a sequence puzzle with pits opening and closing.

Re: trap door sequence

Posted: Thu Sep 20, 2012 5:00 pm
by Grimwold
Ok I had a go at this myself... did a short 5 pit sequence, with at most 2 pits open at a time (to allow for walking between them) and it seemed to work pretty well.

- Create a series of pits and call them sequence_pit_01, sequence_pit_02,sequence_pit_03... etc. (for the purpose of this version of the script we need 5 pits)
- note: it will help understanding the script if you name the pits in the order in which they are to be closed.
- Make sure each pit is a trapdoor!
- Add a timer, name it pit_sequence_timer and set the interval as the length of time between one pit and the next closing.
- Add a script entity, call it pit_sequence and paste in the following script:

Code: Select all

time = 0

function openAllPits()
  for i in allEntities(party.level) do
      if i.id:sub(1,13) == "sequence_pit_" then
         i:open()
      end
   end
end


function startSequence()
  openAllPits()
  pit_sequence_timer:deactivate()
  time = 0
  pit_sequence_timer:activate()
end

function tick()
  if 
    time == 1 
  then
      sequence_pit_01:close()
  elseif 
    time == 2
  then
      sequence_pit_02:close()
  elseif 
    time == 3 then
      sequence_pit_01:open()
      sequence_pit_03:close()
  elseif 
    time == 4 then
      sequence_pit_02:open()
      sequence_pit_04:close()
  elseif 
    time == 5 then
      sequence_pit_03:open()
      sequence_pit_05:close()
  elseif 
    time == 6 then
      sequence_pit_04:open()
  elseif 
    time == 7 then
      sequence_pit_05:open()
      pit_sequence_timer:deactivate()
  end
time = time + 1
end
CONNECTIONS:
- connect the button to the script with the action startSequence
- connect the timer to the script with the action tick



Note: This works for 5 pits, if you want to add more pits it is no problem just add more blocks of elseif time == x statements and refer to the relevant pit names like so:

Code: Select all

  elseif 
    time == 6 then
      sequence_pit_04:open()
      sequence_pit_06:close()
script notes -
* when the button is pushed it first runs a function to open all pits in the level called "sequence_pit_XX"... this is to allow for the situation where the player keeps pressing the button once the sequence has started and forces a reset.
* The initial deactivate of the timer in the start function may not be necessary, but does allow scope for adjusting the interval in the script by first stopping the timer and restarting it. just add a setTimerInterval() command in between.

Re: trap door sequence

Posted: Thu Sep 20, 2012 5:11 pm
by Grimwold
Grimwold wrote: * The initial deactivate of the timer in the start function may not be necessary, but does allow scope for adjusting the interval in the script by first stopping the timer and restarting it. just add a setTimerInterval() command in between.
Just thinking, It may be possible to adjust the timer based on the number of attempts the player has... so each time he falls down a pit, a pad triggers that increases the interval slightly... making the puzzle easier with each failure.

Re: trap door sequence

Posted: Thu Sep 20, 2012 5:20 pm
by Komag
Nice adaptation! I used it before to set up a sequence of teleporters, very fun!

Re: trap door sequence

Posted: Thu Sep 20, 2012 7:45 pm
by papazombie
WOW, it works. thanks :D