Author Topic: Two switches to open a door.  (Read 2343 times)

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Two switches to open a door.
« on: August 07, 2015, 12:55:37 pm »
I wanna have two switches to open a door when they're both activated.

Code: [Select]
if "door_leftswitch:on_activated() and door_rightswitch:on_activated() then
  door_to_b1:is_opening("true")
end

Names:
Switch 1: door_leftswitch
Switch 2: door_rightswitch
Door: door_to_b1

How can do this. I tried to mess around with LUA, but can't figure it out.

the bread

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Two switches to open a door.
« Reply #1 on: August 07, 2015, 01:58:25 pm »
I guess it works like this:
Code: (lua) [Select]
function door_leftswitch:on_activated()
  if door_rightswitch:is_activated() then
    map:open_doors("door_to_b1");
  end
end

function door_rightswitch:on_activated()
  if door_leftswitch:is_activated() then
    map:open_doors("door_to_b1");
  end
end

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Two switches to open a door.
« Reply #2 on: August 07, 2015, 04:47:10 pm »
I've tried that one, but it doesn't work.

the bread

  • Jr. Member
  • **
  • Posts: 67
    • View Profile
Re: Two switches to open a door.
« Reply #3 on: August 07, 2015, 05:30:16 pm »
It does work for me...
Are you trying this in the map script and have you written this line?
Code: (lua) [Select]
local map = ...If your door is not a door entity but a dynamic tile, try this line
Code: (lua) [Select]
door_to_b1:set_enabled(false)instead of map:open_doors()
Anyway, this code
Code: (lua) [Select]
if door_leftswitch:on_activated() and door_rightswitch:on_activated() then
  door_to_b1:is_opening("true")
end
can't work for the following reasons:
1.) on_activated() is a function that is called when the switch is activated. The function that tells you whether the switch is activated is called is_activated()
2.) is_opening is a function that returns a boolean value and doesn't take any parameters. So this won't have any effect.

Zeror

  • Jr. Member
  • **
  • Posts: 88
    • View Profile
Re: Two switches to open a door.
« Reply #4 on: August 08, 2015, 12:44:50 am »
It does work. I made a little error on my side. One of the switches had a spelling error in it's name. Thanks for helping.