Page 1 of 3

Torch activation help please (solution found)

Posted: Wed Sep 19, 2012 4:41 pm
by Neikun
So I have a bunch of torch holders connected to trap doors. Place a torch, trap door closes. I however, cannot figure out how to get the doors to close when a torch is removed.

Re: Torch activation help please

Posted: Wed Sep 19, 2012 4:46 pm
by Montis
Activation event: any.
Action: toggle.

Re: Torch activation help please

Posted: Wed Sep 19, 2012 4:50 pm
by Neikun

Code: Select all

function setorch()
	if setorch: hasTorch=true ()
	then sepit: close()
	end
	if setorch hasTorch=false()
	then sepit: open()
	end
my current code where se means SouthEast
There's a problem with my equal sign. I'm not sure what I've done wrong.
I have to go for a while, but please help.

Re: Torch activation help please

Posted: Wed Sep 19, 2012 4:54 pm
by Montis
you need to use "==", also you're using the brackets in the wrong places.

like

Code: Select all

if setorch:hasTorch() == true then
...
also I don't think you actually need any code here as the torch holders have activate events themselves. so you could just use a connector from the torch holder to the pit with the things I mentioned in my above post.

Re: Torch activation help please

Posted: Wed Sep 19, 2012 4:55 pm
by Shroom
Neikun wrote:

Code: Select all

function setorch()
	if setorch: hasTorch=true ()
	then sepit: close()
	end
	if setorch hasTorch=false()
	then sepit: open()
	end
my current code where se means SouthEast
There's a problem with my equal sign. I'm not sure what I've done wrong.
I have to go for a while, but please help.

Code: Select all

function setorch()
	if setorch:hasTorch() then
	  sepit:close()
	else
	 sepit:open()
	end
end
try that

Re: Torch activation help please

Posted: Wed Sep 19, 2012 6:04 pm
by Komag
this is a good example of something done the straightforward way vs the logical way vs the elegant way, nice!

Re: Torch activation help please

Posted: Wed Sep 19, 2012 10:47 pm
by Neikun
Montis wrote:you need to use "==", also you're using the brackets in the wrong places.

like

Code: Select all

if setorch:hasTorch() == true then
...
also I don't think you actually need any code here as the torch holders have activate events themselves. so you could just use a connector from the torch holder to the pit with the things I mentioned in my above post.
The problem I was having was that I you'd put a torch on the holder and that would activate, but taking on off didn't do anything.

I'm going to try some of the code suggested and let you guys know what worked.

Why do I need == instead of just =
Is there a reason aside from that's just the language?

Re: Torch activation help please

Posted: Wed Sep 19, 2012 10:54 pm
by Neikun
So trying to run the new code,

Code: Select all

function setorch()
   if setorch: hasTorch () == true then :error: attempt to index global 'setorch' (a function value)
   sepit: close()
   else
   sepit: open()
end
end
I get the error after trying to put a torch in the holder.
Any ideas?

Edit: Changed the id of the function to something other than what's triggering the script, no error.

Note: I am still having no luck in getting the pits to open again when the torch is removed.

Re: Torch activation help please

Posted: Wed Sep 19, 2012 11:20 pm
by Shroom
you seem to have lots of spaces everywhere :)

Code: Select all

function setorch()
   if setorch:hasTorch() then
     sepit:close()
   else
     sepit:open()
   end
end
Edit: - ok - thats wierd, it looks like the code identifier was messing with the code i posted earlier too - there should be no spaces after the : or before the ()

Re: Torch activation help please

Posted: Wed Sep 19, 2012 11:26 pm
by Neikun
I use spaces cause I'm afraid of clutter D:
Testing code now.

EDIT: Still does not close when torch is removed.
Does anyone know if this is even possible?

current code:

Code: Select all

function setorchholder()
   if setorch:hasTorch() then
     sepit:close()
   else
     sepit:open()
   end
end
Current results: Place torch on holder, pit closes. Remove torch, pit remains closed. Put torch on holder, pit remains closed.
Expected results: Place torch on holder, pit closes. Remove torch, pit opens. Put torch on holder, pit closes.