I have tested both script, it works not everywhere.
to Thorham :
it works
if I place a shuriken on alcw1 (0.1kg)
2 shuriken on alcw2 (0.2kg)
a branch in alcw3 and alcw4 (1,2 + 1,2 kg)
now if I put 12 shuriken in alcw3 instead of a branch, that don't work anymore, except if I put them one by one.
to JohnWordsworth:
it's the same thing. It depend on which alcove, if you put shurikens instead branchs it don't works.
here is the script, maybe am I configuring it wrong? the alcoves (mine_alcove_1, ..._2, etc..) are relied to the script, with insertItems and removeItems, on the OnAlcoveAct function
Code: Select all
----
-- Given a surface component, get the weight of all items on that surface.
-- Example:
-- local weight = getSurfaceWeight(entity.surface);
-- hudPrint("Surface Weight: " .. weight);
function getSurfaceWeight(surface)
if ( surface == nil ) then
Console.warn("Attempted to measure weight on nil surface.");
return 0;
end
local totalWeight = 0;
for _,item in surface:contents() do
totalWeight = totalWeight + item:getWeight() * item:getStackSize();
end
return totalWeight;
end
----
-- Given a list of names of entities with surfaces, return a table with all of surface weights.
-- Note. This does checks and warns you if you type in the wrong name of a surface.
-- Example:
-- local weights = getManySurfaceWeights({"alcove1", "alcove2"});
-- hudPrint("alcove1 Weighs: " .. weights["alcove1"]);
function getManySurfaceWeights(surfaceNames)
local result = { };
if ( surfaceNames == nil ) then
Console.warn("Attempted to get weights on zero surfaces.");
return result;
end
for _,surfaceName in ipairs(surfaceNames) do
local entity = findEntity(surfaceName);
if ( entity == nil or entity.surface == nil ) then
Console.warn("Surface with name '" .. surfaceName .. "' doesn't exist.");
else
result[surfaceName] = getSurfaceWeight(entity.surface);
end
end
return result;
end
----
-- Function to hook into a surface's onInsertItem and onRemoveItem connectors.
function onAlcoveActivated(sender)
-- For Testing, you could do this...
local weight = getSurfaceWeight(sender);
hudPrint("Stuff Weighs: " .. weight);
-- For your sort of puzzle specifically, you do this...
local weights = getManySurfaceWeights({"mine_alcove_1" , "mine_alcove_2", "mine_alcove_3", "mine_alcove_4"});
if ( weights["mine_alcove_1"] == 0.1 and weights["mine_alcove_2"] == 0.2 and weights["mine_alcove_3"] == 1.2 and weights["mine_alcove_4"] == 1.2) then
hudPrint("HUZZAH");
else
hudPrint("BOO");
end
end
in this configuration, if you put, shurikens on the 1st and 2nd alcove, then branchs on the other alcove, it works very well.
if you replace branchs by shuriken, it don't work anymore
this is the 4th dimension
I have configured the weight in each alcove with different values for alcove 3 and 4, then I filled them only with shurikens.
I don't know why, but I figured that maybe, when the weight get a value > to 1, it goes into another dimension for the stackable items and maybe this goes behind the planck measures
or maybe is it 1.1 there?
mine_alcove_1 = 0.1
mine_alcove_2 = 0.2
mine_alcove_3 = 0.8 1.0
mine_alcove_4 = 0.8 2.0 1.1
works, no doubt on that!
then I ve change the value of the alcove4 to 1.2, it won't work anymore. I got boo, boo, and boo!