set_bit

Declaration

set_bit (bit_field, bit_number: INTEGER; value: BOOLEAN): INTEGER

Description

Returns bit_field with bit bit_number set to value. Does not change bit_field. Use this function with sum_bits to store multiple flags into one variable. This avoids making multiple boolean variables. Bits are numbered from 0. You can set a maximum of 32 bits with this function.

See Also

get_bit
sum_bits
math functions

Example

script test_bits is
  flags := 0
  flags := set_bit (flags, 0, True) -- flags = 1
  flags := set_bit (flags, 7, True) -- flags = 10000001
  total := sum_bits (flags) -- total = 2
  flags := set_bit (flags, 0, False) -- flags = 10000000
  total := sum_bits (flags) -- total = 1
end