Page 1 of 2

moving portal mechanic?

Posted: Fri Sep 21, 2012 9:16 am
by roachburn
You guys probably remember this puzzle from the main game that used this mechanic. So you got a 3X3 square room with a pit in the middle and 2 portals on opposite ends rotating around the room counter clockwise. There are some other elements about the room but that's irrelevant according to what I need to accomplish in my own version of the puzzle. How would I implement this portal rotation? I thought I had a way by putting portals on all squares inside the room and using timers, but the way I had it in my head got too confusing and used too many timers. Any ideas on what to use, be it timers, counters or script? I am definitely interested in multiple way to do it too. Here is a slide show illustration of what I mean if anyone is unable to understand my description. The portals should change every 1 second in a continuous rotation around the room. I want it to be triggered with a hidden pressure plate when entering the room and stopped by another pressure plate on the other end.
Image

Re: moving portal mechanic?

Posted: Fri Sep 21, 2012 9:34 am
by petri
Hint: there are four states, so you need a ticker that goes 0,1,2,3,0,1,2,3,...

Re: moving portal mechanic?

Posted: Fri Sep 21, 2012 9:35 am
by Shroom
an easy way to code it - not elegant but fairly straight forward, would be to use a single timer connected to a lua script with a setting of 1

the script would have a function

Code: Select all

step = 1

function cycleTeleports()

if step==1 then
  telport1:activate()
  telport4:deactivate()
  telport5:activate()
  telport8:deactivate()
  step = 2
else if step==2 then
  telport1:deactivate()
  telport2:activate()
  telport5:deactivate()
  telport6:activate()
  step = 3
else if step==3 then
  telport2:deactivate()
  telport3:activate()
  telport6:deactivate()
  telport7:activate()
  step = 4
else
  telport3:deactivate()
  telport4:activate()
  telport7:deactivate()
  telport8:activate()
  step = 1
end
All we are really doing is building a counter into the script and then turning off two and turning on two each tick of the timer.

The pressure pads would activate and deacivate the timer - you would also have them deactivate all the teleports

Code: Select all


function resetTeleports()
  telport1:deactivate()
  telport2:deactivate()
  telport3:deactivate()
  telport4:deactivate()
  telport5:deactivate()
  telport6:deactivate()
  telport7:deactivate()
  telport8:deactivate()
  step = 1
end
this would need to be in the same script entity as the first script.

Am unable to test this, but it should work - if the second script cant see step, then link it to a counter instead

Re: moving portal mechanic?

Posted: Fri Sep 21, 2012 11:04 am
by Grimwold
I tested this and it worked well, although I needed to fix a couple of minor mistakes in the script (easily done when writing untested code). I also changed the names of the teleporters in the script to the convention used by the editor when placing them.

Code: Select all

step = 1

function cycleTeleports()
    if step==1 then
      teleporter_1:activate()
      teleporter_4:deactivate()
      teleporter_5:activate()
      teleporter_8:deactivate()
      step = 2
    elseif step==2 then
      teleporter_1:deactivate()
      teleporter_2:activate()
      teleporter_5:deactivate()
      teleporter_6:activate()
      step = 3
    elseif step==3 then
      teleporter_2:deactivate()
      teleporter_3:activate()
      teleporter_6:deactivate()
      teleporter_7:activate()
      step = 4
    elseif step==4 then
      teleporter_3:deactivate()
      teleporter_4:activate()
      teleporter_7:deactivate()
      teleporter_8:activate()
      step = 1
    end
end

function resetTeleports()
  teleporter_1:deactivate()
  teleporter_2:deactivate()
  teleporter_3:deactivate()
  teleporter_4:deactivate()
  teleporter_5:deactivate()
  teleporter_6:deactivate()
  teleporter_7:deactivate()
  teleporter_8:deactivate()
  step = 1
end
In addition to the script you will need

- a timer with interval 1 second and with action point at the script entity cycleTeleports
- start pressure plate with 2 CONNECTORS
---- one to the script entity resetTeleporters
---- one to the timer with an activate action
- end pressure plate
with 2 CONNECTORS
---- one to the script entity resetTeleporters
---- one to the timer with an deactivate action

Re: moving portal mechanic?

Posted: Fri Sep 21, 2012 4:19 pm
by Komag
Yeah, it's threads like this that really peel back the curtain ;)

and this would probably make a decent addition to the Useful scripts repository

Re: moving portal mechanic?

Posted: Sat Sep 22, 2012 6:28 am
by roachburn
Thanks for all the advice guys. I managed to get this to work. I was also able to adapt it to some other puzzles I made. This dungeon is coming along nicely!

Re: moving portal mechanic?

Posted: Fri Oct 05, 2012 7:37 am
by akroma222
Thank you guys!! rotating teleporters are now on the menu ;)

Re: moving portal mechanic?

Posted: Mon Jan 21, 2013 12:49 pm
by bravocharlie
can we play wwe with tihs?

Re: moving portal mechanic?

Posted: Mon Jan 21, 2013 4:45 pm
by Komag
what's wwe?

Re: moving portal mechanic?

Posted: Tue Jan 22, 2013 2:22 am
by Neikun
I think it's just a typo. "Can we play with this?"