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!
function levertoggler()
if lowertrigger1.floortrigger:isActivated() then
upper_lever1.lever:toggle()
lower_lever2.lever:toggle()
end
if lowertrigger2.floortrigger:isActivated() then
lower_lever1.lever:toggle()
lower_lever3.lever:toggle()
upper_lever2.lever:toggle()
end
if lowertrigger3.floortrigger:isActivated() then
lower_lever2.lever:toggle()
upper_lever3.lever:toggle()
end
if uppertrigger1.floortrigger:isActivated() then
lower_lever1.lever:toggle()
upper_lever2.lever:toggle()
end
if uppertrigger2.floortrigger:isActivated() then
lower_lever2.lever:toggle()
upper_lever1.lever:toggle()
upper_lever3.lever:toggle()
end
if uppertrigger3.floortrigger:isActivated() then
lower_lever3.lever:toggle()
upper_lever2.lever:toggle()
end
end
I have 6 levers in a 2x3 arrangement. When I pull one lever, I want the adjacent ones to toggle. I thought I was being clever with this script by putting an invisible floortrigger in front of each lever. but its giving me a stack overflow error. I think its getting itself into some kind of infinite loop anyway.
I figured it out. I just needed to make each lever connect to a unique function. Works perfect now. Can someone explain why the first case gave me a problem?
function levertog1()
if lowertrigger1.floortrigger:isActivated() then
upper_lever1.lever:toggle()
lower_lever2.lever:toggle()
end
end
function levertog2()
if lowertrigger2.floortrigger:isActivated() then
lower_lever1.lever:toggle()
lower_lever3.lever:toggle()
upper_lever2.lever:toggle()
end
end
function levertog3()
if lowertrigger3.floortrigger:isActivated() then
lower_lever2.lever:toggle()
upper_lever3.lever:toggle()
end
end
function levertog4()
if uppertrigger1.floortrigger:isActivated() then
lower_lever1.lever:toggle()
upper_lever2.lever:toggle()
end
end
function levertog5()
if uppertrigger2.floortrigger:isActivated() then
lower_lever2.lever:toggle()
upper_lever1.lever:toggle()
upper_lever3.lever:toggle()
end
end
function levertog6()
if uppertrigger3.floortrigger:isActivated() then
lower_lever3.lever:toggle()
upper_lever2.lever:toggle()
end
end
Because when you toggle a lever, it triggers its connectors just like it was pulled. Let's say you pulled the lever corresponding to lowertrigger1: your script sees that you're standing on the corresponding floor trigger, so it toggles upper_lever1. upper_level1 is connected to the levertoggler() function, so it gets called again. It sees that lowertrigger1 is activated, so it toggles upper_lever1. This calls the function again, which sees that lowertrigger1 is activated, which toggles upper_lever1, which calls the function again, which sees that lowertrigger1 is activated, which calls the function again...