[Help] Remove torch from holder script?

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
DrMadolite
Posts: 27
Joined: Mon Nov 05, 2012 10:26 pm
Location: Norway

[Help] Remove torch from holder script?

Post by DrMadolite »

Hey guys, I'm trying to make a script where a torch is removed from its holder when a pressure plate is stepped on. Simple enough, but I'm still fussy on LUA syntax :( Any help?

Thanks in advance.
Last edited by DrMadolite on Wed Nov 14, 2012 1:41 am, edited 1 time in total.
The torch is your friend.
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: [Help] Remove torch from holder script?

Post by Neikun »

A clunky workaround might be to destroy the torch holder with the torch in it while simultaneously spawning an empty one?
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
DrMadolite
Posts: 27
Joined: Mon Nov 05, 2012 10:26 pm
Location: Norway

Re: [Help] Remove torch from holder script?

Post by DrMadolite »

Neikun wrote:A clunky workaround might be to destroy the torch holder with the torch in it while simultaneously spawning an empty one?
How do you do that? I'm sorry, I'm a complete newbie. :D
The torch is your friend.
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: [Help] Remove torch from holder script?

Post by Neikun »

You can destroy it with
<your torch name>: destroy()

As for spawning a torch hodler on a wall, I'm a little fuzzier on the details.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: [Help] Remove torch from holder script?

Post by crisman »

You'll have to take the coordinates of the torch holder. the script should looks like:

function torches()

torch_holder_i:destroy()
spawn("torch_holder", party.level, x, y, facing, "torch_holder_i")
--gave an ID to the torch holder so you can repeat the script as you wish

end

Ps: this script will only extinguish the torch inside the torch holder. I think its a beautiful effect!! :D
If you want to actually destroy the torch, well... I'll have to figure it out, because, right now, I don't know :D
User avatar
DrMadolite
Posts: 27
Joined: Mon Nov 05, 2012 10:26 pm
Location: Norway

Re: [Help] Remove torch from holder script?

Post by DrMadolite »

Ok thanks guys. I decided not to use this event though, as I found another interesting puzzle algorithm. Plus I just wanna be done with my dungeon soon, without spending too much time learning advanced LUA.

Cheers. :)
The torch is your friend.
jsi7iv
Posts: 3
Joined: Mon Jul 01, 2013 10:27 pm

Re: [Help] Remove torch from holder script?

Post by jsi7iv »

Here is some code that I found solved this issue for me. It will remove the old torch holder, any torches, and then spawn a new one. It is um... ugly, but hey it works.

Code: Select all

function leftEyeRemoved()

	-- cycle through items at my torch holder location
	for k in entitiesAt(party.level, 4, 17) do
	
		-- if the items name has "torch" then destroy/remove the item
		if string.find(k.name, "torch") then
			k:destroy()		
		end

	end
	
	-- Spawn a new torch holder at the exact same location, with the same id. This allows for continued use if desired	
	spawn("torch_holder", party.level, 4, 17, 3, "eyeTorchLeft")

end
Just updated the code. Should have made it check for torches or items with names like "torch", and not remove everything :lol:
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: [Help] Remove torch from holder script?

Post by Eightball »

crisman wrote:You'll have to take the coordinates of the torch holder. the script should looks like:

Code: Select all

function torches()

torch_holder_i:destroy()
spawn("torch_holder", party.level, x, y, facing, "torch_holder_i")
--gave an ID to the torch holder so you can repeat the script as you wish

end
Ps: this script will only extinguish the torch inside the torch holder. I think its a beautiful effect!! :D
If you want to actually destroy the torch, well... I'll have to figure it out, because, right now, I don't know :D
This little trick helped me immensely. I actually set out to do the same thing as the original poster: remove a torch from it's holder. But that torch holder also has about five connectors. After destroying it and replacing it, how can I add the connectors again? I've tried adding lines after the spawn line with "torchholder:addconnector()" but I get this error: "attempt to index global 'torch_holder_10' (a nil value)". Here's my code...

Code: Select all

-- Starts a timer for function torchSnuffed()
-- extinguishes a torch placed in the holder after 1 second.
function noTorch4U()
	if torch_holder_10:hasTorch() == true then
	timer_noTorch4U:activate()
	end
end

-- appears to snuff out the torch in the holder by destroying
-- the holder and instantly adding a new one.
function torchSnuffed()
	torch_holder_10:destroy()
	spawn("torch_holder", party.level, 21, 5, 1, "torch_holder__10")
		torch_holder_10:addConnector("activate", temple_door_darkness, "close")
end
--gave an ID to the torch holder so you can repeat the script as you wish
I think the new torch_holder doesn't really effectively have a torch in it. It just appears to (which is why it appears extinguished). So adding connectors before the extinguished torch is "removed" by the player shouldn't be a problem... in theory.
User avatar
DesperateGames
Posts: 90
Joined: Sun Oct 06, 2013 1:54 pm

Re: [Help] Remove torch from holder script?

Post by DesperateGames »

Have not tested it, but the issue seems to be that the ID of the newly spawned torchholder has a double underscore __ in it:

"torch_holder__10"

This is why you can't attach the connectors because "torch_holder_10" does not exist anymore ;-)

Besides this, this procedure should work, I have done a similiar thing in my mod.
User avatar
Eightball
Posts: 48
Joined: Thu Jan 09, 2014 8:21 am

Re: [Help] Remove torch from holder script?

Post by Eightball »

whoooops. Thank you for pointing out that typo. Now the error to the addConnector problem is "bad argument #2 to 'addConnector' (string expected, got table). I wish I knew what that meant. It turned out to be another problem like the typo.

Since I've just been guessing using other people's code from the forum, I sometimes have to experiment with punctuation and syntax. So I tried putting the id of the door in quotes and that seemed to fix my next problem. Works like a charm now! Thanks again!

The corrected code should read (DestroysTorchLight is the name of my script with the following two functions. the connectors could be anything one wants them to be, but mine end up teleporting the party out the door they just came in and unceremoniously slamming it behind them as the torch is snuffed out):

Code: Select all

-- Starts a timer for function torchSnuffed()
-- extinguishes a torch placed in the holder after 1 second.
function noTorch4U()
	if torch_holder_10:hasTorch() == true then
	timer_noTorch4U:activate()
	end
end

-- appears to snuff out the torch in the holder by destroying
-- the holder and instantly adding a new one.
function torchSnuffed()
	torch_holder_10:destroy()
	spawn("torch_holder", party.level, 21, 5, 1, "torch_holder_10")
		torch_holder_10:addConnector("activate", "teleporter_5", "activate")
		torch_holder_10:addConnector("activate", "timer_1", "activate")
		torch_holder_10:addConnector("activate", "timer_2", "activate")
		torch_holder_10:addConnector("activate", "teleporter_9", "activate")
		torch_holder_10:addConnector("activate", "DestroysTorchlight", "noTorch4U")
end
--gave an ID to the torch holder so you can repeat the script as you wish
Post Reply