Need help with a script

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
LittleDragon
Posts: 2
Joined: Tue Nov 06, 2018 6:58 pm

Need help with a script

Post by LittleDragon » Tue Nov 06, 2018 7:22 pm

Hello there!
I'm quite new to modding and an absolute noob when it comes to scripting.
But since I'm working on my own dungeon I though I'd give it a try and I ended up confused...
I've tried to use the script from this post viewtopic.php?f=22&t=8214 for a simple puzzle, where you just need to walk in a circle and therefore removed everything that has to do with the torches and the light.
That's what I finally got:

Code: Select all

pathcount = 0
pathsolved = 0

function pathpuzzlecircle()
	if pathsolved == 0 then
		local currentactivated = {}
		for i = 1,12 do
			currentactivated[i] = findEntity("pathtrigger"..i)
			if currentactivated[i].floortrigger:isActivated() then
				if i == pathcount + 1 then
					pathcount = pathcount + 1
					if pathcount == 12 then
						return invisible_wall_182: destroy()
						end
				elseif i == pathcount then
					--do nothing
				elseif i == 1 then 
					--start reset
					pathcount = 1
				else
					-- total reset
					pathcount = 0
				end
			end
		end
	end
end
And i ended up with "attempt to index a nil value X" for line 9. And I'm pretty sure there's more that's wrong...
Sadly I'm still learning about lua, which is why I can't figure out, what to do in order to make it work and I'm grateful for anyone, how can help me here :)

SluisE
Posts: 8
Joined: Fri Nov 30, 2018 4:56 pm

Re: Need help with a script

Post by SluisE » Fri Nov 30, 2018 5:06 pm

Do you have the entities pathtrigger1, pathtrigger2...pathtrigger12 named in your mod. Remember, the names are case-sensitive, so pathTrigger1 will not be found.

Plus, when the player solves the puzzle the variable pathsolved is not set to 1

And when you destroy the wall, don't use a space between the ":" and "destroy()"

LittleDragon
Posts: 2
Joined: Tue Nov 06, 2018 6:58 pm

Re: Need help with a script

Post by LittleDragon » Sat Dec 01, 2018 2:14 pm

Thank you so much for answering :)
I've corrected everything and it now works perfectly fine!

Post Reply