Scripting an alcove puzzle

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
Isaac_the_Khajiit
Posts: 3
Joined: Wed May 27, 2020 4:35 pm

Scripting an alcove puzzle

Post by Isaac_the_Khajiit »

I'm trying to script an alcove to open a door when a specific item is inserted.

I've found tons of example scripts on this forum, but none of them work. I am a complete scripting novice. I know I need to swap out the names of the door, alcove, and items with my own names, but beyond that I can't understand what I'm doing wrong.

http://www.grimrock.net/modding_log1/ho ... ve-puzzle/ The script I found here crashes the editor.
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Scripting an alcove puzzle

Post by Zo Kath Ra »

Board index < Legend of Grimrock 2 < Mod Creation
http://www.grimrock.net/modding_log1/ho ... ve-puzzle/

Do you want to make a script for Grimrock 1 or 2 ?
Isaac_the_Khajiit
Posts: 3
Joined: Wed May 27, 2020 4:35 pm

Re: Scripting an alcove puzzle

Post by Isaac_the_Khajiit »

Grimrock 2.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Scripting an alcove puzzle

Post by Isaac »

Connect the alcove to this script; adjust the door id, and the item name to suit.

Code: Select all

function checkItem(surface, item)
	if item.go.name == "rock" then 					--target item name
		local door = findEntity('dungeon_door_wooden_1')	--target door id 
		if door then
			door.door:open()
		end
	end
end
Welcome to the forum. ;)
User avatar
Zo Kath Ra
Posts: 931
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Scripting an alcove puzzle

Post by Zo Kath Ra »

Isaac_the_Khajiit wrote: Fri May 29, 2020 4:42 pm Grimrock 2.
In LoG 2, it's simpler:

Code: Select all

function itemPuzzle(caller, item)
	if item.go.name == "pitroot_bread" then
		playSound("level_up")
	end
end
"caller" contains the alcove's Surface component.
"item" contains the inserted object's Item component.
".go" references the component's game object.
(LoG 1 didn't have components)

To learn more about the differences between LoG 1 and LoG 2 scripting, I'd recomend the LoG 2 modding guide:
http://www.grimrock.net/modding/
Isaac_the_Khajiit
Posts: 3
Joined: Wed May 27, 2020 4:35 pm

Re: Scripting an alcove puzzle

Post by Isaac_the_Khajiit »

Thank you both!
Post Reply