LoG2 Editor features and modding

Talk about anything related to Legend of Grimrock 2 here.
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: LoG2 Editor features and modding

Post by Isaac »

This goes in a script, and each torch_holder needs connected with an onInsertItems, and an onRemoveItems.
(For some reason ther is no 'alwaysActivate' option.)

Code: Select all

function deactivateForcefield()

	if 	 torch_holder_1.controller:getHasTorch() and
		 torch_holder_2.controller:getHasTorch() and
		 torch_holder_3.controller:getHasTorch() then
		
		force_field_1.controller:activate()
	else
		force_field_1.controller:deactivate()		
	end
end
An alternative method for this is the following:

Code: Select all

function deactivateForcefield()
	if torch_counter_1.counter:getValue() > 2 then --was >=
			force_field_1.controller:activate()
	elseif torch_counter_1.counter:getValue() < 1 then --was >=
			force_field_1.controller:deactivate()
	end
end
The feature of this one is that you have to have all three torches inserted or removed, before seeing the result.
This script additionally requires a counter named "torch_counter_1"; initially set to zero (if all holders start with torches).
Last edited by Isaac on Sun Nov 02, 2014 6:22 pm, edited 1 time in total.
whackangel
Posts: 49
Joined: Wed Sep 26, 2012 3:50 pm

Re: LoG2 Editor features and modding

Post by whackangel »

Well, I'm feeling very unlucky with scripting... none of the options are working... It's either not working at all and the force_field remains active, or a red 'nil value' in the script that pops up...

I reaaly need to learn how to script properly for LoG... maybe some tutorial (other than those already existent) should be usefull. Thaks anyways Isaac !
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: LoG2 Editor features and modding

Post by Isaac »

To use that script, you place a script object on the map and paste one or the other of those code blocks in it; then select each one of the torch_holders and add two connections to the script; one "onInsertItem" connection, and one for "onRemoveItem".

For the alternate script ~specific, you need to add a counter named: torch_counter_1
and add two connections to it from each torch; onInsertItems / increment and onRemoveItems / decrement.
Image

https://www.dropbox.com/s/1w2gv3v2vvclq ... t.avi?dl=0

*I have made a needed change to the alternate script, so for that one use this updated version.

Code: Select all

    function deactivateForcefield()
       if torch_counter_1.counter:getValue() > 2 then
             force_field_1.controller:activate()
       elseif torch_counter_1.counter:getValue() < 1 then
             force_field_1.controller:deactivate()
       end
    end
___________________

BTW: If all you want is to turn off the force-field when all of the torches are removed... The quickest way is to place a counter, and set it to the number of torches, then connect it to the force-field; set it to deactivate. Then connect each torch to the counter; set to decrement on removal. This won't turn the field back on when the torches are replaced.
whackangel
Posts: 49
Joined: Wed Sep 26, 2012 3:50 pm

Re: LoG2 Editor features and modding

Post by whackangel »

All right!! I've started over the room to 'clean' it from possible f*ckups... retried the scripting part... and it worked !! I just don't understand why it didn't worked before since I've change nothing in the script...

Like I said before, it might be helpfull to know what "objects" are scriptable : by object I mean, for this example, it was .controller that was the main object... sometimes it's not that obvious (at least to me).

Anyways, thank you very much for the help... I'm sure I'll be back in no time with another unsolvable scripting issue :D
Post Reply