Is it with this script also possible to open more than one door?
like:
SpoilerShow
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?
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,
-- 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)
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?
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.
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.
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.
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.