Page 2 of 3
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 9:28 pm
by dnaeil
Is it with this script also possible to open more than one door?
like:
counter = 0
-- insert name of door within quotes
rune_doors_name = "rune_door_1", "rune_door_2", "rune_door_3"
-- insert names of plates, in order, within brackets
runes = { "rune_1",
"rune_2",
"rune_3",
"rune_4",
"rune_5",
"rune_6" }
for i = 1, #runes do
local current_plate = findEntity(runes)
current_plate:addConnector("activate", self.id, "isPressed")
current_plate:setTriggeredByParty(true)
current_plate:setTriggeredByMonster(false)
current_plate:setTriggeredByItem(false)
end
function isPressed()
counter = counter + 1
local correct_plate = findEntity(runes[counter])
local rune_doors = findEntity(rune_doors_name)
if not correct_plate:isDown() then
counter = 0
end
if counter == #runes then
rune_doors:open()
counter = 0
end
end
The script works, but only one door opens. Have i build a string to open all, like the string with the plates/runes?
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 10:11 pm
by Ryeath_Greystalk
I think the issue is with your first line assigning the door names.
-- insert name of door within quotes
rune_doors_name = "rune_door_1", "rune_door_2", "rune_door_3"
I still get confused by this stuff but it appears to me that you are trying to assign 3 values to a single variable. You will probably need to turn it into a table and then rework the last part of the script to recognize the individual elements. Possibly something like,
rune_doors_name = {"rune_door1","rune_door_2","rune_door_3"}
then at the end use your indexing like earlier to find the door name you need.
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 10:46 pm
by dnaeil
Ok thanks! My new atempt ist that:
counter = 0
-- insert name of door within quotes
rune_doors_name = { "rune_door_1",
"rune_door_2",
"rune_door_3" }
-- insert names of plates, in order, within brackets
runes = { "rune_1",
"rune_2",
"rune_3",
"rune_4",
"rune_5",
"rune_6" }
for i = 1, #runes do
local current_plate = findEntity(runes)
current_plate:addConnector("activate", self.id, "isPressed")
current_plate:setTriggeredByParty(true)
current_plate:setTriggeredByMonster(false)
current_plate:setTriggeredByItem(false)
end
for i = 1, #rune_doors_name do
local rune_doors = findEntity(rune_doors_name)
rune_doors:setDoorState(closed)
end
function isPressed()
counter = counter + 1
local correct_plate = findEntity(runes[counter])
local current_plate = findEntity(runes)
local rune_doors = findEntity(rune_doors_name)
if not correct_plate:isDown() then
counter = 0
end
if counter == #runes then
rune_doors:open()
counter = 0
end
end
But this gives me the error: bad argument #1 to 'setDoorState' (string expected, got nil)
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 11:17 pm
by Komag
add quotes: "closed"
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 11:20 pm
by Ryeath_Greystalk
That error tells you to put the state in quotes.
You have
rune_doors:setDoorState(closed)
try
rune_doors:setDoorState("closed")
edit: Komag beat me to it. That's what I get for answering the phones in the middle of a reply.
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Tue Jul 30, 2013 11:47 pm
by dnaeil
ohhh...what a slip. Thanks!
I tried it and now there is another error: bad argument #1 to 'findEntity' (string expected, got nil)
function isPressed()
counter = counter + 1
local correct_plate = findEntity(runes[counter])
local current_plate = findEntity(runes) <------ to this file, but this worked before I added the things above...!?
local rune_doors = findEntity(rune_doors_name)
Another little question: What causes framerate collapses in certain rooms? When I leave the framerate-drop room all works fine?
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Wed Jul 31, 2013 12:44 am
by Ryeath_Greystalk
I think the issue is "i" is not defined in your function.
In your first posted scripted the function isPressed() only uses the counter variable.
in your second posted script the function isPressed() uses the "i" variable which was part of the loop you used earlier in the program. I don't believe that the function isPressed() has access to that variable.
As for the drop in frame rate the first thing to look at is how many light sources are in a room. Lights are the biggest resource hog.
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Wed Jul 31, 2013 12:59 am
by dnaeil
Thanks. I understand more and more. But how can i bind the into the function. My plan is, that not only one door opens, when the right sequence of pressure plates is pressed, but several. In a distinct order ...and closing, when you walk the wrong way.
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Wed Jul 31, 2013 1:22 am
by Ryeath_Greystalk
Try defining a variable outside of the loop and adjusting it's value from within the loop.
local loop_counter = 0
for i = 1, #runes do
loop_counter = i
local current_plate = findEntity(runes)
current_plate:addConnector("activate", self.id, "isPressed")
current_plate:setTriggeredByParty(true)
current_plate:setTriggeredByMonster(false)
current_plate:setTriggeredByItem(false)
end
function isPressed()
counter = counter + 1
local correct_plate = findEntity(runes[counter])
local current_plate = findEntity(runes[loop_counter])
local rune_doors = findEntity(rune_doors_name[loop_counter])
if not correct_plate:isDown() then
counter = 0
end
May or may not work, not sure. Just threw it out there as I'm leaving work and will be offline for a few hours. If it doesn't I'm sure one of the other helpful people here will point you in the right direction, and if not I will look at it later this evening.
Re: Scripting a Pressure Plate puzzle - Help!
Posted: Thu Aug 01, 2013 1:05 am
by Ryeath_Greystalk
Sorry I did not get a chance to get on the computer last night. I dabbled a bit with it before work this morning but didn't get to far. I will keep plugging away at it though.