Solarus-Games English Forum

Solarus => Development => Topic started by: Zeror on August 07, 2015, 12:55:37 PM

Title: Two switches to open a door.
Post by: Zeror on August 07, 2015, 12:55:37 PM
I wanna have two switches to open a door when they're both activated.


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.
Title: Re: Two switches to open a door.
Post by: the bread 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
Title: Re: Two switches to open a door.
Post by: Zeror on August 07, 2015, 04:47:10 PM
I've tried that one, but it doesn't work.
Title: Re: Two switches to open a door.
Post by: the bread 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.
Title: Re: Two switches to open a door.
Post by: Zeror 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.