Item on Alcove Puzzle Issue

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

Item on Alcove Puzzle Issue

Post by haffhedd »

Hey Guys!

Brand new to Lua and modding for Legend of Grimrock.

My question is a pretty simple one but the solution may not be as straightforward.

How do I create an 'item on alcove puzzle' where putting the correct item on an alcove opens a door and removing the item closes the door.

I've read the modding guide and the solution they provide is to use this code:

Code: Select all

function itemPuzzle()
   -- iterate through all contained items on alcove, checking for a matching name
   for i in itemPuzzleAlcove:containedItems() do
      if i.name == "pitroot_bread" then
         playSound("level_up")
         break
      end
   end
end
Then add a connector to the script_entity that is activated always. The connector I made for the door to be opened is set to

Code: Select all

(any, *doorname*, toggle)
The door opens/closes when an item is placed/removed, as intended.

The problem with this approach is that while the correct item triggers the sound effect and activates the connector to open the door, any other item I use also opens the door. The only difference is that the incorrect item doesn't trigger the sound effect. Obviously this shouldn't happen.

How would I alter the code/change the connector so that only the correct item activates the connector? Any other item placed on the Alcove should do nothing.

Thanks in advance.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Item on Alcove Puzzle Issue

Post by Isaac »

haffhedd wrote: How would I alter the code/change the connector so that only the correct item activates the connector? Any other item placed on the Alcove should do nothing.

Thanks in advance.
You can remove the connections, and activate the door with the onInsertItem hook on a custom cloned alcove.

Code: Select all

-- Place in object.lua
cloneObject{
name = "trigger_alcove", 
baseObject = 'temple_alcove',  --or other alcove
onInsertItem = function(alcove, item) if item.name == "pitroot_bread" then
playSound("level_up")
trigger_door:toggle()  -- Your custom door
end,
}
This works (unless I made a typo/error)... by calling the onInsertItem block when the player clicks on the alcove with the item on the mouse cursor. This happens before the the alcove accepts the item.

Returning False, from here will refuse the action.

Returning... alcove:getItemCount() == 0
will restrict the alcove to holding only a single item at a time.

Alternatively: You can call your itemPuzzle() function from within the hook [full path], and add the door:toggle() in that function instead.

*Changes to object.lua, or other start-up scripts, requires a full reload of the project to see the change in the editor.
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

Re: Item on Alcove Puzzle Issue

Post by haffhedd »

Isaac wrote:snip
Thanks for the help! It's really appreciated.

That said, I ran into a script error. I followed your script and replaced the assets as appropriate.

Here's my code. Let me know if I did anything wrong. This was inserted into the objects.lua file in my dungeon folder.

Code: Select all

cloneObject{
name = "itemPuzzleAlcove1", 
baseObject = 'dungeon_alcove',  --or other alcove
onInsertItem = function(alcove, item) if item.name == "dagger" then
playSound("level_up")
puzzledoor1:toggle()  -- Your custom door
end,
}
The error I got was (object.lua location) " unexpected symbol near ' , ' ". Removing the comma gets a different error: "unexpected symbol near ' } ' ". Is the cloneObject function not closing correctly?

Just out of curiosity, what is the benefit of cloning the alcove? Also, why is it necessary to make the change outside of the editor?

Thanks again.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Item on Alcove Puzzle Issue

Post by Isaac »

Yeah, it looks like I forgot a closing " End " for the IF block.... Just a moment...

Code: Select all

cloneObject{
name = "itemPuzzleAlcove1",
baseObject = 'dungeon_alcove',  --or other alcove
onInsertItem = function(alcove, item) if item.name == "dagger" then
			playSound("level_up")
			puzzledoor1:toggle()  -- Your custom door
return true  -- This allows the dagger to be placed on the shelf
			end
			end,
}
Cloning [for the most part] just a time saver; you could completely define the object instead.

** If you add a connection to the puzzledoor1, set "close" and by 'deactivate', and not set to 'always activate'... the door will close when you remove the dagger.
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

Re: Item on Alcove Puzzle Issue

Post by haffhedd »

Tried the new code.

No longer get the error but placing the dagger on the Alcove does nothing with the code above.

Am I missing a step?

Thanks,
- Haff
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Item on Alcove Puzzle Issue

Post by Isaac »

haffhedd wrote:Tried the new code.

No longer get the error but placing the dagger on the Alcove does nothing with the code above.

Am I missing a step?

Thanks,
- Haff
Possibly...I tested it this last time.

The steps should be:
Add the definition to object.lua
Add the door; (in this case double check the names, and check letter case.)
Add the 'deactivate' / 'close' connection from the alcove to the door (optional).
Reload

Placing the dagger should open the door, and removing it should close the door ~if you added the connection for that.

https://www.dropbox.com/s/rhmu8ukt81xli ... r_door.avi

Image
haffhedd
Posts: 6
Joined: Wed May 21, 2014 5:49 pm

Re: Item on Alcove Puzzle Issue

Post by haffhedd »

Aha!

Figured out what the issue was. I didn't replace the Alcove with the cloned asset (did I mention I'm new? :P). Neat! Works perfectly now.

Once again, thanks for the help and your patience.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Item on Alcove Puzzle Issue

Post by Isaac »

Glad to help.
Image
User avatar
Eleven Warrior
Posts: 752
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Item on Alcove Puzzle Issue

Post by Eleven Warrior »

Onya Issac your a real Champ bro good job :)
Post Reply