lua questions - altar item puzzle opens door but won't close

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

lua questions - altar item puzzle opens door but won't close

Post by Eightball »

I'm a newb at this, and I couldn't find any answers after a couple hours on forums, so here I am asking...

The idea is to open a door by placing a water_flask on an altar (altar_2). I got that to work. But now for the sake of consistency, have been trying to make the door close as soon as player removes the water_flask from the altar. I think I need a second if/then statement to make the altar check after activating the door once. Anyway, can anyone explain why this if/then/else isn't working the way I think it should? Thanks.

Code: Select all

function WaterOffering()
   for i in altar_2:containedItems() do
      if i.name == "water_flask" then
  		 waterLocked_door:open()
      else
         waterLocked_door:close()
      end
   end
end
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: lua questions - altar item puzzle opens door but won't c

Post by alois »

Did you set the altar to "activate always"? And 'any' in the targeting section of the altar?
Anyway, there is a problem with the code: if you put - say - a water flask on the altar, and then a stone, the door may close (which is not what you want).

Code: Select all

function WaterOffering()
   local is_water = false
   for i in altar_2:containedItems() do
      if i.name == "water_flask" then
         is_water = true
      end
   end
   if (is_water) then 
      waterLocked_door:open()
   else
      waterLocked_door:close()
   end
end
In this way, the code checks whether there is a water_flask on the altar and opens the door if there is, and closes it if there is not.

alois :)
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: lua questions - altar item puzzle opens door but won't c

Post by Eightball »

That code did the trick!
Thank you so much, Alois.
That will help me with several puzzles that I could come up with!

Funny sidenote: When I tested your code, I accidentally discovered by the way I put the altar in the room that I could just chuck the glass flask at it and it would always land perfectly on the altar.
Post Reply