Scripting a Pressure Plate puzzle - Help!

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
dnaeil
Posts: 9
Joined: Fri Apr 13, 2012 2:44 pm
Location: Germany

Re: Scripting a Pressure Plate puzzle - Help!

Post by dnaeil »

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?
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting a Pressure Plate puzzle - Help!

Post 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.
User avatar
dnaeil
Posts: 9
Joined: Fri Apr 13, 2012 2:44 pm
Location: Germany

Re: Scripting a Pressure Plate puzzle - Help!

Post by dnaeil »

Ok thanks! My new atempt ist that:
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

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)
User avatar
Komag
Posts: 3658
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Scripting a Pressure Plate puzzle - Help!

Post by Komag »

add quotes: "closed"
Finished Dungeons - complete mods to play
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting a Pressure Plate puzzle - Help!

Post 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. :lol:
User avatar
dnaeil
Posts: 9
Joined: Fri Apr 13, 2012 2:44 pm
Location: Germany

Re: Scripting a Pressure Plate puzzle - Help!

Post 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?
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting a Pressure Plate puzzle - Help!

Post 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.
User avatar
dnaeil
Posts: 9
Joined: Fri Apr 13, 2012 2:44 pm
Location: Germany

Re: Scripting a Pressure Plate puzzle - Help!

Post 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.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting a Pressure Plate puzzle - Help!

Post 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.
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: Scripting a Pressure Plate puzzle - Help!

Post 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.
Post Reply