Code: Select all
isFinished = false
function checkAlcoves()
if isFinished == true then
return
end
if testWeight(alcw1, 0.1) and
testWeight(alcw2, 0.2) and
testWeight(alcw3, 1.2) and
testWeight(alcw4, 1.2) then
iron_weight.door:open()
playSound("secret")
isFinished = true
else
iron_weight.door:close()
end
end
function testWeight(alcove, weight)
local a
local b = 0
local c = weight * 10000
for _, a in alcove.surface:contents() do
b = b + (a:getWeight() * a:getStackSize() * 10000)
end
if round(b) == round(c) then
return true
end
return false
end
function round(a)
local b, c
b, c = math.modf(a)
if c >= 0.5 then
return b + 1
end
return b
end
Code: Select all
function round(a)
local b, c
b, c = math.modf(a)
if c >= 0.5 then
return b + 1
end
return b
end