i'm having trouble here
I have another puzzle where I want a teleporter to activate but only when 4 power gems are placed on an altar.
I have 4 power gems i placed in the editor for testing purposes and i linked the altar to this script
but when i place the 4 gems in the altar, the teleporter won't activate.
however, on a separate occasion, i had accidentally typed activate instead of deactivate in the "else" section and the teleporter activated when i placed 1 gem on the altar
probably because the script checked for a correct solution and didn't find it so it executed the "else" command to activate the teleporter.
what i want is for it to check the altar for the 4 gems and only activate the teleporter when all 4 gems are on the altar.
I don't know what i'm doing wrong here.
Code: Select all
function Win()
local gem1 = false
local gem2 = false
local gem3 = false
local gem4 = false
for _,itm in altar_1.surface:contents() do
if itm.go.name == "power_gem_item_1" then
gem1 = true
break
end
end
for _,itm in altar_1.surface:contents() do
if itm.go.name == "power_gem_item_2" then
gem2 = true
break
end
end
for _,itm in altar_1.surface:contents() do
if itm.go.name == "power_gem_item_3" then
gem3 = true
break
end
end
for _,itm in altar_1.surface:contents() do
if itm.go.name == "power_gem_item_4" then
gem4 = true
break
end
end
if gem1 and gem2 and gem3 and gem4 then
teleporter_3.controller:activate()
else
teleporter_3.controller:deactivate()
end
end