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!
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.
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.
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!)
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!
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
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
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.