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 » Fri May 29, 2020 1:41 am

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.

Zo Kath Ra
Posts: 829
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Scripting an alcove puzzle

Post by Zo Kath Ra » Fri May 29, 2020 5:46 am

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 » Fri May 29, 2020 4:42 pm

Grimrock 2.

User avatar
Isaac
Posts: 2949
Joined: Fri Mar 02, 2012 10:02 pm

Re: Scripting an alcove puzzle

Post by Isaac » Fri May 29, 2020 5:16 pm

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. ;)

Zo Kath Ra
Posts: 829
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Scripting an alcove puzzle

Post by Zo Kath Ra » Fri May 29, 2020 5:27 pm

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 » Fri May 29, 2020 6:08 pm

Thank you both!

Post Reply