Help: levers that move another levers.
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Help: levers that move another levers.
Well, after almost one hour trying to find a solution, even using counters and pressure plates, zero results.
I'm trying to make a copy of the Keelbreach southern puzzle where you have lots of levers, and each lever moves the 2 nearest ones. I'm tyring to use the connectors, but it seems that another lever can't be referred for this.
I'm quite desesperated and I can promise I searched in the forum for some reference to this kind of puzzle, but I wasn't lucky.
Is there any solution without recurring to scripting? If not... any suggestions about how to script this stuff? I only need at least one line of the code to understand how it works...
Aaaaaaaaaargh!
Thanks in advance!!
I'm trying to make a copy of the Keelbreach southern puzzle where you have lots of levers, and each lever moves the 2 nearest ones. I'm tyring to use the connectors, but it seems that another lever can't be referred for this.
I'm quite desesperated and I can promise I searched in the forum for some reference to this kind of puzzle, but I wasn't lucky.
Is there any solution without recurring to scripting? If not... any suggestions about how to script this stuff? I only need at least one line of the code to understand how it works...
Aaaaaaaaaargh!
Thanks in advance!!
Re: Help: levers that move another levers.
Something like this should work:
I am a lua noob as well (but trying to get better), so someone better could point out a more efficient way of doing it or point out one of my mistakes. 
Code: Select all
function pullLever()
if lever_1.lever:isActivated() then
lever_2.lever:setState("activated")
lever_3.lever:setState("deactivated")
end

- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Help: levers that move another levers.
Thanks a lot for the quick answer>Grimfan wrote:Something like this should work:
I am a lua noob as well (but trying to get better), so someone better could point out a more efficient way of doing it or point out one of my mistakes.Code: Select all
function pullLever() if lever_1.lever:isActivated() then lever_2.lever:setState("activated") lever_3.lever:setState("deactivated") end
I tried this>
Code: Select all
function pullLever()
if beach_lever_4:isActivated() then
beach_lever_8:setState("Deactivated")
beach_lever_10:setState("Deactivated")
end
if beach_lever_4:isDeactivated() then
beach_lever_8:setState("Activated")
beach_lever_10:setState("Activated")
end
end
Why??

Thanks in advance again.
Re: Help: levers that move another levers.
You need to call the component. In this case the lever (beach_lever_1.lever not just beach_lever_1).
This works.
Again, the scripting maestros may have an even better way.
Code: Select all
function pullLever()
if beach_lever_1.lever:isActivated() then
beach_lever_2.lever:setState("activated")
beach_lever_3.lever:setState("activated")
else
if beach_lever_1.lever:isDeactivated() then
beach_lever_2.lever:setState("deactivated")
beach_lever_3.lever:setState("deactivated")
end
end
end
Again, the scripting maestros may have an even better way.
-
- Posts: 168
- Joined: Thu Oct 30, 2014 1:56 am
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Help: levers that move another levers.
Great answers from great people!!! Thanks Grimfan and GoldenShadowGS.
It was such an easy problem... I'm sorry, begginer level on scripting still...
About the other one it seems to be risky in order to do a puzzle with a douzen of levers calling each others, and I want to be sure that the puzzle is free of bugs and it has only one solution.
Thanks again, I'll post you back about the results of the puzzle.
It was such an easy problem... I'm sorry, begginer level on scripting still...
About the other one it seems to be risky in order to do a puzzle with a douzen of levers calling each others, and I want to be sure that the puzzle is free of bugs and it has only one solution.
Thanks again, I'll post you back about the results of the puzzle.
Re: Help: levers that move another levers.
Say you have levers named "lever_1", "lever_2" etc...
make sure the lever-names are unique to the puzzle, otherwise you risk flipping levers outside of what was intended.
They are placed in order.
Say you want to toggle the levers on both sides of lever_2, that would be lever_1 and lever_3, so 2-1 and 2+1
make sure the lever-names are unique to the puzzle, otherwise you risk flipping levers outside of what was intended.
They are placed in order.
Say you want to toggle the levers on both sides of lever_2, that would be lever_1 and lever_3, so 2-1 and 2+1
Code: Select all
function toggleLever(sender)
-- "sender" here is a bit of magic, it contains the lever calling the function.
-- so with a bit of more magic, we can find out what this lever has as its id-number
local leverid = tonumber(string.match(sender.go.id, "^lever_(.*)"))
--then it's simple to toggle the levers on each side.
local leftLever = findEntity("lever_"..leverid-1)
local rightLever = findEntity("lever_"..leverid+1)
-- we need to check if theese lever exists, so...
if leftLever then
--then we toggle it...
if leftLever.lever:isActivated() then
leftLever.lever:setState("deactivated")
else
leftLever.lever:setState("activated")
end
end
-- and the same for the right one...
if rightLever then
--then we toggle it...
if rightLever.lever:isActivated() then
rightLever.lever:setState("deactivated")
else
rightLever.lever:setState("activated")
end
end
end
Links to my YouTube playlist of "tutorials" and to my forum thread.
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Help: levers that move another levers.
THAT is EXACTLY what I was looking for. How did I not find it before!!??
I saw this in the Scripting Reference:
LeverComponent:getDisableSelf()
LeverComponent:getSound()
LeverComponent:isActivated()
LeverComponent:isDeactivated()
LeverComponent:setDisableSelf(boolean)
LeverComponent:setSound(string)
LeverComponent:setState(state)
LeverComponent:toggle()
LeverComponent.onActivate(self)
LeverComponent.onDeactivate(self)
LeverComponent.onToggle(self)
So I guess that this is ALL the actions/options you can manage to do puzzles with levers. That is a lot, considering the posibilities.
Guys, you're awesome, I love you in an heterosexual way. I'll give you credits for your support!
I saw this in the Scripting Reference:
LeverComponent:getDisableSelf()
LeverComponent:getSound()
LeverComponent:isActivated()
LeverComponent:isDeactivated()
LeverComponent:setDisableSelf(boolean)
LeverComponent:setSound(string)
LeverComponent:setState(state)
LeverComponent:toggle()
LeverComponent.onActivate(self)
LeverComponent.onDeactivate(self)
LeverComponent.onToggle(self)
So I guess that this is ALL the actions/options you can manage to do puzzles with levers. That is a lot, considering the posibilities.
Guys, you're awesome, I love you in an heterosexual way. I'll give you credits for your support!
- TheLastOrder
- Posts: 104
- Joined: Wed Oct 17, 2012 1:56 am
Re: Help: levers that move another levers.
Prozail wrote:Say you have levers named "lever_1", "lever_2" etc...
make sure the lever-names are unique to the puzzle, otherwise you risk flipping levers outside of what was intended.
They are placed in order.
Say you want to toggle the levers on both sides of lever_2, that would be lever_1 and lever_3, so 2-1 and 2+1
Code: Select all
function toggleLever(sender) -- "sender" here is a bit of magic, it contains the lever calling the function. -- so with a bit of more magic, we can find out what this lever has as its id-number local leverid = tonumber(string.match(sender.go.id, "^lever_(.*)")) --then it's simple to toggle the levers on each side. local leftLever = findEntity("lever_"..leverid-1) local rightLever = findEntity("lever_"..leverid+1) -- we need to check if theese lever exists, so... if leftLever then --then we toggle it... if leftLever.lever:isActivated() then leftLever.lever:setState("deactivated") else leftLever.lever:setState("activated") end end -- and the same for the right one... if rightLever then --then we toggle it... if rightLever.lever:isActivated() then rightLever.lever:setState("deactivated") else rightLever.lever:setState("activated") end end end
The 2nd "end" is unnecessary, or it won't work. So this is what I have>
function toggleLever(sender)
local leftLever = findEntity("kb_lever_02")
local rightLever = findEntity("kb_lever_06")
if leftLever.lever:isActivated() then
leftLever.lever:setState("deactivated")
else
leftLever.lever:setState("activated")
end
if rightLever then
if rightLever.lever:isActivated() then
rightLever.lever:setState("deactivated")
else
rightLever.lever:setState("activated")
end
end
end
It's working and it's amazing!!! Thanks again guys!