Page 1 of 2

[Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 12:57 am
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.

Re: [Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 1:26 am
by Neikun
A clunky workaround might be to destroy the torch holder with the torch in it while simultaneously spawning an empty one?

Re: [Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 1:30 am
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

Re: [Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 1:38 am
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.

Re: [Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 2:12 am
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

Re: [Help] Remove torch from holder script?

Posted: Wed Nov 14, 2012 3:38 am
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. :)

Re: [Help] Remove torch from holder script?

Posted: Tue Jul 02, 2013 3:58 am
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:

Re: [Help] Remove torch from holder script?

Posted: Wed Jan 15, 2014 3:55 pm
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.

Re: [Help] Remove torch from holder script?

Posted: Wed Jan 15, 2014 4:56 pm
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.

Re: [Help] Remove torch from holder script?

Posted: Thu Jan 16, 2014 3:23 am
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