How to script torch holders?
How to script torch holders?
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?
still in the LoG2 editor there is some kind of difference and I can't do it
it sais "attempt to call method 'hasTorch' (a nil value)"
Code: Select all
if t1.controller:HasTorch() == true then
d1.door:open()
else
d1.door:close()
end
Re: How to script torch holders?
I think you have to use "set" and "get" such as:
Code: Select all
t1.controller:getHasTorch()
Re: How to script torch holders?
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
but of course getHasTorch() is much easier in when you already know how to get the value 
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

Re: How to script torch holders?
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?
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 yetobject71 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"

- Mysterious
- Posts: 226
- Joined: Wed Nov 06, 2013 8:31 am
Re: How to script torch holders?
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 2object71 wrote:still in the LoG2 editor there is some kind of difference and I can't do it
it sais "attempt to call method 'hasTorch' (a nil value)"Code: Select all
if t1.controller:HasTorch() == true then d1.door:open() else d1.door:close() end



- Mysterious
- Posts: 226
- Joined: Wed Nov 06, 2013 8:31 am
Re: How to script torch holders?
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?
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