Page 1 of 2
help with checker room puzzle script
Posted: Wed Sep 19, 2012 12:23 pm
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"
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!
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 12:34 pm
by Grimwold
I think you need
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.
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 12:46 pm
by Komag
(need to remove the repeat of plate1)
also you'll need to make sure the other plates are UP
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 12:56 pm
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.
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 1:04 pm
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!)
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 1:17 pm
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!
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 1:22 pm
by roachburn
Ok I fixed it. I renamed the door to checkerdoor1 and it fixed the issue. Thanks guys!
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 1:24 pm
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
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 2:33 pm
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.
Re: help with checker room puzzle script
Posted: Wed Sep 19, 2012 3:49 pm
by Billick
Don't forget the checkered room has 2 solutions