Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Lua treats all number variables as floats. Forcing a cast to integer with math.floor gave better results.
Modulo (%) returns a non-integer if passed a non-integer so may need wrapped also.
Maybe better to rework the math logic if bit positions are the target?

1/31/2023 9:48:19 PM line = 290 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 299 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 307 : value1 = 1  value2 = 0 value3 = 0 value4 = 14
1/31/2023 9:48:19 PM line = 315 : value1 = 1  value2 = 0 value3 = 0 value4 = 14

2.1 – Values and Types

There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.

Number represents real (double-precision floating-point) numbers.

   cmdindex = 10
   tox_flag = 65

    tox_flag_reliablesn = math.floor(tox_flag/64)

    tox_flag_reliablesn = tox_flag_reliablesn%2

    tox_flag_frag = math.floor(tox_flag/128)
    print("tox_flag_frag =", tox_flag_frag)

    tox_flag_life =  math.floor(tox_flag/32)

    tox_flag_life = (tox_flag_life%2

3.4.1 – Arithmetic Operators

Modulo is defined as

 a % b == a - math.floor(a/b)*b

That is, it is the remainder of a division that rounds the quotient towards minus infinity.

Lua treats all number variables as floats. Forcing a cast to integer with math.floor gave better results.
Modulo (%) returns a non-integer if passed a non-integer so may need wrapped also.
Maybe better to rework the math logic if bit positions are the target?

1/31/2023 9:48:19 PM line = 290 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 299 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 307 : value1 = 1  value2 = 0 value3 = 0 value4 = 14
1/31/2023 9:48:19 PM line = 315 : value1 = 1  value2 = 0 value3 = 0 value4 = 14

2.1 – Values and Types

There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.

Number represents real (double-precision floating-point) numbers.

   cmdindex = 10
   tox_flag = 65

    tox_flag_reliablesn = math.floor(tox_flag/64)

    tox_flag_reliablesn = tox_flag_reliablesn%2

    tox_flag_frag = math.floor(tox_flag/128)
    print("tox_flag_frag =", tox_flag_frag)

    tox_flag_life =  math.floor(tox_flag/32)

    tox_flag_life = (tox_flag_life%2

3.4.1 – Arithmetic Operators

Modulo is defined as

 a % b == a - math.floor(a/b)*b

That is, it is the remainder of a division that rounds the quotient towards minus infinity.

Lua treats all number variables as floats. Forcing a cast to integer with math.floor gave better results.
Modulo (%) returns a non-integer if passed a non-integer so may need wrapped also.
Maybe better to rework the math logic if bit positions are the target?

1/31/2023 9:48:19 PM line = 290 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 299 : value1 = 1  value2 = 0 value3 = 0 value4 = 10
1/31/2023 9:48:19 PM line = 307 : value1 = 1  value2 = 0 value3 = 0 value4 = 14
1/31/2023 9:48:19 PM line = 315 : value1 = 1  value2 = 0 value3 = 0 value4 = 14

2.1 – Values and Types

There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.

Number represents real (double-precision floating-point) numbers.

   cmdindex = 10
   tox_flag = 65

    tox_flag_reliablesn = math.floor(tox_flag/64)

    tox_flag_reliablesn = tox_flag_reliablesn%2

    tox_flag_frag = math.floor(tox_flag/128)
    print("tox_flag_frag =", tox_flag_frag)

    tox_flag_life =  math.floor(tox_flag/32)

    tox_flag_life = (tox_flag_life%2

3.4.1 – Arithmetic Operators

Modulo is defined as

 a % b == a - math.floor(a/b)*b

That is, it is the remainder of a division that rounds the quotient towards minus infinity.

20 – The String Library

The function string.format is a powerful tool when formatting strings, ...

Changing the debug line from integer (%d) to floats (%f) :

    local message = string.format("line = %f : value1 = %f  value2 = %f value3 = %f value4 = %f", lineno, value1, value2, value3, value4)

shows that the variables are non-zero values.

2/1/2023 10:50:31 AM line = 290.000000 : value1 = 1.015625  value2 = 0.031250 value3 = 0.507813 value4 = 10.000000
2/1/2023 10:50:31 AM line = 299.000000 : value1 = 1.015625  value2 = 0.031250 value3 = 0.507813 value4 = 22.000000
2/1/2023 10:50:31 AM line = 307.000000 : value1 = 1.015625  value2 = 0.031250 value3 = 0.507813 value4 = 26.000000
2/1/2023 10:50:31 AM line = 315.000000 : value1 = 1.015625  value2 = 0.031250 value3 = 0.507813 value4 = 30.000000