Logic Machine Forum
Boolean object operations - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Boolean object operations (/showthread.php?tid=2807)



Boolean object operations - davidchispas - 25.08.2020

I need to do a sum with 1 bit objects, is this possible?

For example,
a = 1/1/1 (true)
b = 1/1/2 (false)
c = 1/1/3 (true)
value = 1/1/4

a + b + c = value

*in this operation it would send a value 2


RE: Boolean object operations - admin - 25.08.2020

Like this:
Code:
objs = {
  '1/1/1',
  '1/1/2',
  '1/1/3',
}

sum = 0
for _, obj in ipairs(objs) do
  if grp.getvalue(obj) then
    sum = sum + 1
  end
end

grp.checkwrite('1/1/4', sum)



RE: Boolean object operations - davidchispas - 25.08.2020

(25.08.2020, 14:29)admin Wrote: Like this:
Code:
objs = {
  '1/1/1',
  '1/1/2',
  '1/1/3',
}

sum = 0
for _, obj in ipairs(objs) do
  if grp.getvalue(obj) then
    sum = sum + 1
  end
end

grp.checkwrite('1/1/4', sum)

Thank you so much Admin!  Smile