Page 3 of 3
Re: Lever Puzzle Scripting Help
Posted: Fri Jan 04, 2013 6:55 am
by Babby Tutel
Well after toying with the map a bit I realized five levers is a terrible number because you solve it just by hitting the first and fourth levers. So I extended it to six, and used Das's code out of curiosity since I probably want to be able to easily edit the code if need be.
Code works fine, but it only works one way. If a lever is re-deactivated it is preferrable that the involved levers around it also re-deactivate in puzzles like this.
How would one include both activation and deactivation? I don't think the code is recognizing when the lever is toggled from the "activated" to the "deactivated" state. Otherwise it's perfect and a bit more user-friendly than Wold's, albeit his worked in the both lever states.
Re: Lever Puzzle Scripting Help
Posted: Fri Jan 04, 2013 7:31 am
by dasarby
Six levers will have the same problem; just hit switches 2 and 4.
Really, you probably either need to either start some switches up, and some down, or make it a little less predictable by connecting switches to other switches besides just their neighbors. Maybe 6 on either side of a hallway? Anything to make the player have to figure out the pattern.
I'm not quite sure what you mean by the second part? Do you mean that when a lever is switched back into the up position (up == deactive, down == active), that the connected switches are not toggling again? My script should behave that way. Can you check that the connectors between the levers and the script are on the "any" event and not "activate"?
If you mean the puzzle should be "solved" when all levers are in the same state, regardless of what that state is (i.e. solved means all levers up OR all levers down), then that's a simple change to the script:
Code: Select all
locked = false
levers = {
lever1={"lever2"},
lever2={"lever1", "lever3"},
lever3={"lever2", "lever4"},
lever4={"lever3", "lever5"},
lever5={"lever4"}
}
function Solved()
eg_door:open()
end
function UnSolved()
eg_door:close()
end
function PullLever(trigger)
if not locked then
locked = true
if levers[trigger.id] then
for _, id in ipairs(levers[trigger.id]) do
findEntity(id):toggle()
end
end
locked = false
local allActive = true
local allDeactive = true
for id, _ in pairs(levers) do
allActive = allActive and findEntity(id):getLeverState() == "activated"
allDeactive = allDeactive and findEntity(id):getLeverState() == "deactivated"
end
if allActive or allDeactive then
Solved()
else
UnSolved()
end
end
end
Just remember that unless you start some switches activated, using this script will actually start the puzzle in a solved state!
Re: Lever Puzzle Scripting Help
Posted: Fri Jan 04, 2013 11:09 pm
by Babby Tutel
Shit. This is why I need to stop bringing my laptop to bed. You're right about 6 being no better than 5. I will, though, go to 8 levers and changing the way they activate eachother. Now that I look at it most numbers can easily be solved in just two or three lever pulls if done in the previous format.
I was saying that when you activate a deactivated lever, it will activate the levers beside it as well. But if you deactivate a lever, it does not deactivate the levers around it. Sorry for weird wording, I've been getting to sleep at about 1 AM all week because of procrastinating on the internet.
You were right, I just overlooked the connector event and didn't set it to any. So this is basically case closed, and thanks to you three for helping me out. Glad to hear your script is in the repository, it's a great reference.
Re: Lever Puzzle Scripting Help
Posted: Fri Jan 04, 2013 11:52 pm
by Komag
I haven't added it to the repository, I just suggested it was good and he should add it

Re: Lever Puzzle Scripting Help
Posted: Fri Jan 04, 2013 11:54 pm
by Babby Tutel
If that's the case, then I say go for it.
Re: Lever Puzzle Scripting Help
Posted: Sat Jan 05, 2013 7:41 am
by dasarby
Thanks for the feedback! I'll post this to the scripts thread.
I went through and comment the script, explaining how to use and configure it; and added the script to github:
https://github.com/adharris/grimrock/bl ... Levers.lua