How to script torch holders?

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
object71
Posts: 3
Joined: Mon Oct 27, 2014 9:23 pm

How to script torch holders?

Post 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.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: How to script torch holders?

Post by NutJob »

object71
Posts: 3
Joined: Mon Oct 27, 2014 9:23 pm

Re: How to script torch holders?

Post 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)"
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: How to script torch holders?

Post by Lark »

I think you have to use "set" and "get" such as:

Code: Select all

t1.controller:getHasTorch()
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: How to script torch holders?

Post 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 :)
object71
Posts: 3
Joined: Mon Oct 27, 2014 9:23 pm

Re: How to script torch holders?

Post 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"
User avatar
Jouki
Posts: 127
Joined: Fri Oct 24, 2014 12:57 pm

Re: How to script torch holders?

Post 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
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: How to script torch holders?

Post 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 :)
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: How to script torch holders?

Post 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
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: How to script torch holders?

Post 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
Post Reply