First off, if the 3 Rocks are a "pile" - a single Rock Item with a Count of 3 - I had no idea how to use Lua Script to get the count. However, I was able to acquire the Weight of the Rock pile. In LoG 2, a Rock weighs 0.7 kg. Thus, I was able to say, "if RockWeight == 0.7 * 11 then DoSomething();"
This seemed to work just fine for smaller numbers, and with any combination of Rock piles. For example, if I need to check for 3 Rocks (0.7 * 3) then the Player could successfully do the following:
1) 3 different Rock piles each with a count of 1, for 3 Rocks total
2) A single Rock pile with a count of 3, for 3 Rocks total
3) 2 different Rock piles, one with a count of 2 and another with a count of 1, for 3 Rocks total.
Each time, the LUA Script properly evaluates that the accumulative Weight of the rocks within the Aclove is in fact, 0.7 * 3.
My problem? This completely fails when the Rock count is 7. If I do the following this theory falls apart:
1) 3 different Rock piles, one with a count of 5, one with a count of 1, another with a count of 1, for 7 Rocks total.
In this case, the LUA script does in fact calculate the weight as 4.9 (0.7 * 7), but if I evaluate it with an IF/Then statement, the condition fails:
if RockWeight == (0.7 * 7) then DoSomething(); end
It makes no sense. If I use a Print command, I can clearly see the RockWeight is "4.9" and the result of "0.7 * 7" is also 4.9; which means the If/Then statement in LUA is failing when it says "does 4.9 == 4.9"
If, however, the Player simply puts in a single Rock pile with a count of 7, the very same If/Then statement evaluates successfully.
Anyone else deal with something like this?
Code: Select all
for v,item in tree_aclove_1.surface:contents() do
if item.go.name == "rock" then
rockWeight = item:getTotalWeight();
if rockWeight ~= nil then
totalWeight = totalWeight + rockWeight;
end
end
end