help with checker room puzzle script

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
roachburn
Posts: 17
Joined: Wed Sep 19, 2012 11:22 am

help with checker room puzzle script

Post by roachburn »

I am trying to recreate the checkered room puzzle with 9 pressure plates using a lua script. when testing this as soon as i put a rock on the pressure plate, I crash back to the editor and I get the error under the first line of code saying "attempt to call method "activate" (a nil value) x"
SpoilerShow
function checkerdoor()
if checkerplate1:activate() == true and
checkerplate1:activate() == true and
checkerplate3:activate() == true and
checkerplate5:activate() == true and
checkerplate7:activate() == true and
checkerplate9:activate() == true then
checkerdoor:activate()
else
checkerdoor:deactivate()
end
end
what am i doing wrong? is there a better way to code this? Thanks for the help!
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: help with checker room puzzle script

Post by Grimwold »

I think you need

Code: Select all

checkerplate1:isDown()
and so on...

I'm also pretty sure you don't need == true with boolean values..

So (without being able to test it myself), I think your code should be:

Code: Select all

function checkTheDoor()
  if checkerplate1:isUp() and
     checkerplate2:isDown() and
     checkerplate3:isUp() and
     checkerplate4:isDown() and
     checkerplate5:isUp() and
     checkerplate6:isDown() and
     checkerplate7:isUp() and
     checkerplate8:isDown() and
     checkerplate9:isUp()
   then
     checkerdoor:activate()
  else
     checkerdoor:deactivate()
  end
end

edit - corrected for comments made below by Komag and Montis.
Last edited by Grimwold on Wed Sep 19, 2012 2:43 pm, edited 3 times in total.
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: help with checker room puzzle script

Post by Komag »

(need to remove the repeat of plate1)

also you'll need to make sure the other plates are UP
Finished Dungeons - complete mods to play
User avatar
Montis
Posts: 340
Joined: Sun Apr 15, 2012 1:25 am
Location: Grimrock II 2nd playthrough (hard/oldschool)

Re: help with checker room puzzle script

Post by Montis »

Grimwold wrote:edit - final thing... you would need to connect this script twice from each pressure plate. once with an activate and again with a deactivate action... then the test is done every time the state of any plate is changed.
actually you only need to connect it once on the "any" event.
When destiny calls, the chosen have no choice.

My completed dungeon (LoG1): Hypercube
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: help with checker room puzzle script

Post by Grimwold »

Thanks for the corrections guys! I've edited my reply above... This is what comes of not being able to test stuff. (so I'm gonna see if the editor will actually run on this PC!)
roachburn
Posts: 17
Joined: Wed Sep 19, 2012 11:22 am

Re: help with checker room puzzle script

Post by roachburn »

Thanks for the tips. I am still getting an error at the last line checkerdoor:deactivate() attempt to index global "checkerdoor" (a funtion value) x

I wish I knew what these errors mean then i could probably fix it on my own but I am just not familiar with programming. I am learning quite a bit though, so thanks for that!
roachburn
Posts: 17
Joined: Wed Sep 19, 2012 11:22 am

Re: help with checker room puzzle script

Post by roachburn »

Ok I fixed it. I renamed the door to checkerdoor1 and it fixed the issue. Thanks guys!
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: help with checker room puzzle script

Post by Komag »

Here is my version that works:
- plates are all linked to script with "any"
- door is ID "checkeredport"
- the up/down patter allows entry/exit from both middle ends

Code: Select all

function openport()
  if checkerplate1:isUp() and
     checkerplate2:isDown() and
     checkerplate3:isUp() and
     checkerplate4:isDown() and
     checkerplate5:isUp() and
     checkerplate6:isDown() and
     checkerplate7:isUp() and
     checkerplate8:isDown() and
     checkerplate9:isUp()
  then
     checkeredport:open()
  else
     checkeredport:close()
  end
end
Finished Dungeons - complete mods to play
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: help with checker room puzzle script

Post by Grimwold »

roachburn wrote:Ok I fixed it. I renamed the door to checkerdoor1 and it fixed the issue. Thanks guys!
Yeah, I failed to notice that the door and the function had the same name. I have edited my script to change the function name in case anyone else reads this... it should now be very similar to Komag's version.
User avatar
Billick
Posts: 201
Joined: Thu Apr 19, 2012 9:28 pm

Re: help with checker room puzzle script

Post by Billick »

Don't forget the checkered room has 2 solutions :D
Halls of Barrian - current version 1.0.3 - Steam Nexus
Me Grimrock no bozo!
Post Reply