Page 1 of 2

How to script torch holders?

Posted: Mon Oct 27, 2014 10:33 pm
by object71
I looked the forums but still didn't quite find how to make a door open by checking if there is a torch in the torch holder.

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 10:38 pm
by NutJob

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 10:52 pm
by object71
still in the LoG2 editor there is some kind of difference and I can't do it

Code: Select all

if t1.controller:HasTorch() == true then
	d1.door:open()
else
	d1.door:close()
end
it sais "attempt to call method 'hasTorch' (a nil value)"

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 11:16 pm
by Lark
I think you have to use "set" and "get" such as:

Code: Select all

t1.controller:getHasTorch()

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 11:22 pm
by Jouki
yeah Lark is right, but whenever you can't get the value (true/false) cause of not knowing a name you can use the counter. for example on torch holder: onInsertItem increment and OnRemoveItem decrement then launch the script

Code: Select all

function torchDoor()
	if counter_1.counter:getValue() == 1 then
	   dungeon_door_portcullis_1.door:open()
	else
	   dungeon_door_portcullis_1.door:close()
	end
end
but of course getHasTorch() is much easier in when you already know how to get the value :)

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 11:32 pm
by object71
I knew that I could get the value with a counter and so on but wanted to see how to do it with a single script. The thing is I'm trying to learn scripting (I'm a begginer programer and I'm on a pretty basic lvl) I was missing that the code is actually "getHasTorch"

Re: How to script torch holders?

Posted: Mon Oct 27, 2014 11:36 pm
by Jouki
object71 wrote:I knew that I could get the value with a counter and so on but wanted to see how to do it with a single script. The thing is I'm trying to learn scripting (I'm a begginer programer and I'm on a pretty basic lvl) I was missing that the code is actually "getHasTorch"
actually it's not about being begginer but sometimes it could be pretty hard estimate what name guys from AM used until we don't have documentation yet :P

Re: How to script torch holders?

Posted: Tue Oct 28, 2014 7:06 am
by Mysterious
object71 wrote:still in the LoG2 editor there is some kind of difference and I can't do it

Code: Select all

if t1.controller:HasTorch() == true then
	d1.door:open()
else
	d1.door:close()
end
it sais "attempt to call method 'hasTorch' (a nil value)"
I would also like to know how to Script a Torch Puzzle with lua guys. I have 8 x torches in a room each one will either need a torch or wont. Log 1 it was easy but now the code does not work anymore in Log 2 :( I don't want to use counter(s) to do the puzzle. Just how it use to be in Log 1 :). The reason I don't want to use counter(s) is it clogs up the level to much, as Komag once said it is neater to have script do things rather than counters, timers etc... all over the screen level. Wise words man :)

Re: How to script torch holders?

Posted: Tue Oct 28, 2014 7:32 am
by Mysterious
Ok I have 2 torch holders named t1 and t2. The first to Scripts work, but the 3rd Script does not. Does anyone know how to fix this I have tried for 3 hours lol. :)

Code: Select all

--- Torch holder set: onremoveItem
--- false = Door will open or

--- Torch holder set: onInsertItem
--- true = Door will open

function TorchTestb()

if t1.controller:getHasTorch() == false then
   dungeon_secret_door_10.door:open()
else
   dungeon_secret_door_10.door:close()
end
	end

function TorchTestc()

if t1.controller:getHasTorch() == true then
   dungeon_secret_door_10.door:open()
else
   dungeon_secret_door_10.door:close()
end
	end

--- If it do this with 2 x Torches it wont work.
--- It comes up with Error: unexpected symbol near 'if'

function TorchPuzzle1()

if t1.controller:getHasTorch() == true and
if t2.controller:getHasTorch() == true then  ---Error is here---

   dungeon_secret_door_10.door:open()
else
   dungeon_secret_door_10.door:close()
end
	end

Re: How to script torch holders?

Posted: Tue Oct 28, 2014 11:16 am
by Prozail
you're on the right track.

Code: Select all

function TorchPuzzle1()
    if t1.controller:getHasTorch() and t2.controller:getHasTorch() then
        dungeon_secret_door_10.door:open()
    else
        dungeon_secret_door_10.door:close()
    end
end