Lever combination puzzle

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Lever combination puzzle

Post by Emera Nova »

I'd like to make a puzzle using the state of levers to make a door open, what type of script would I need to make it so a few levers had to be in a certain order to open a door.
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: Lever combination puzzle

Post by Skuggasveinn »

Lever puzzle was I think covered in part 7 of the tutorials I made.
https://www.youtube.com/watch?v=-YlAZwq ... e=youtu.be

The script used there was this, mind you it was 2 doors and 3 levers, and different combo used to open each door with a button if the combo of the levers was correct, but it will hopefully get you in the right direction.
SpoilerShow

Code: Select all

function firetrappuzzle1()

   --local count1 = firecounter_1.counter:getValue()
   --local count2 = firecounter_2.counter:getValue()
   --local count3 = firecounter_3.counter:getValue()

   if firecounter_1.counter:getValue() == 0 and
   firecounter_2.counter:getValue() == 1 and
   firecounter_3.counter:getValue() == 0 then

   --hudPrint("firecounter_1 has "..count1.." in value")
   --hudPrint("firecounter_2 has "..count2.." in value")
   --hudPrint("firecounter_3 has "..count3.." in value")
   mine_door_spear_1.door:open()

   else
   mine_door_spear_1.door:close()
   --hudPrint("firecounter_1 has "..count1.." in value")
   --hudPrint("firecounter_2 has "..count2.." in value")
   --hudPrint("firecounter_3 has "..count3.." in value")
   end
   
end


function firetrappuzzle2()

   --local count1 = firecounter_1.counter:getValue()
   --local count2 = firecounter_2.counter:getValue()
   --local count3 = firecounter_3.counter:getValue()

   if firecounter_1.counter:getValue() == 1 and
   firecounter_2.counter:getValue() == 0 and
   firecounter_3.counter:getValue() == 0 then

   --hudPrint("firecounter_1 has "..count1.." in value")
   --hudPrint("firecounter_2 has "..count2.." in value")
   --hudPrint("firecounter_3 has "..count3.." in value")
   mine_door_spear_2.door:open()

   else
   mine_door_spear_2.door:close()
   --hudPrint("firecounter_1 has "..count1.." in value")
   --hudPrint("firecounter_2 has "..count2.." in value")
   --hudPrint("firecounter_3 has "..count3.." in value")
   end
   
end

function resetdoors()
   
   if mine_door_spear_1.door:isOpen() == true or
   mine_door_spear_2.door:isOpen() == true then
   mine_door_spear_1.door:close()
   mine_door_spear_2.door:close()
   
   else
   
   end
   
end
Skuggasveinn.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Lever combination puzzle

Post by Emera Nova »

So I'm watching the video and trying to edit the code to work with what I'm trying to do.

SpoilerShow
function LeverCheck()

--local count1 = counter_11.counter:getValue()
--local count2 = counter_12.counter:getValue()
--local count3 = counter_13.counter:getValue()

if counter_11.counter:getValue() == 0 and
counter_12.counter:getValue() == 1 and
counter_13.counter:getValue() == 0 then

--hudPrint("counter_11 has "..count1.." in value")
--hudPrint("counter_12 has "..count2.." in value")
--hudPrint("counter_13 has "..count3.." in value")
timer_25:activate()

else
timer_25:deactivated()
--hudPrint("counter_11 has "..count1.." in value")
--hudPrint("counter_12 has "..count2.." in value")
--hudPrint("counter_13 has "..count3.." in value")
end

end
I'm attempting to do a check on the levers like you did in the video and then if it passes activate a timer that will turn on a string of magic bridges. And if it fails the check to keep the timer off, what term is needed to tell it to turn on and off the timer.

Should I cut out the middle man of the timer and just have the script turn on and off the magic bridges if the code has been put in correctly. Either way what is the term that it needs to have it stay deactivated if the levers are the wrong way.


*Edit: Neveeer mind I think i found what I needed to do, I was looking at some other code on the forums and I saw this .controller, I attached that to the script and replaced the timer with the bridge to cut out the middle man and that appears to have worked.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: Lever combination puzzle

Post by Azel »

You dont need Timers for this specific task. So it would just be your, bridge_id.controller:activate() and bridge_id.controller:deactivate() as needed.

Although if you do want to use a timer in the future, it would be, timer_25.timer:start() and timer_25.timer:stop(), respectively.

There are a few types of Commands to use, so be sure to research when each is appropriate:

1) :enable() and :disable()
2) :activate() and :deactivate()
3) :start() and :stop()
4) :increment() and :decrement()

Just a few examples.
Post Reply