Assign multiple variables = true (or false) ??

I need a little help with how to sort and compress code…

For the following code, is there any way to write the shortest code, iterating or something like that, to avoid repeating so much?

if ( value == 0 ) then
     add_point_1 = true add_point_2 = true add_point_3 = true add_point_4 = true add_point_5 = true add_point_6 = true add_point_7 = true add_point_8 = true add_point_9 = true add_point_10 = true
    add_point_11 = true add_point_12 = true add_point_13 = true add_point_14 = true add_point_15 = true add_point_16 = true add_point_17 = true add_point_18 = true add_point_19 = true add_point_20 = true
    add_point_21 = true add_point_22 = true add_point_23 = true add_point_24 = true add_point_25 = true add_point_26 = true add_point_27 = true add_point_28 = true add_point_29 = true add_point_30 = true
    add_point_31 = true add_point_32 = true
  end
  if ( value == 1 ) then
     add_point_1 = false add_point_2 = true add_point_3 = true add_point_4 = true add_point_5 = true add_point_6 = true add_point_7 = true add_point_8 = true add_point_9 = true add_point_10 = true
    add_point_11 = true add_point_12 = true add_point_13 = true add_point_14 = true add_point_15 = true add_point_16 = true add_point_17 = true add_point_18 = true add_point_19 = true add_point_20 = true
    add_point_21 = true add_point_22 = true add_point_23 = true add_point_24 = true add_point_25 = true add_point_26 = true add_point_27 = true add_point_28 = true add_point_29 = true add_point_30 = true
    add_point_31 = true add_point_32 = true
  end
  
  --etc etc etc

  if ( value == 32 ) then
     add_point_1 = false add_point_2 = false add_point_3 = false add_point_4 = false add_point_5 = false add_point_6 = false add_point_7 = false add_point_8 = false add_point_9 = false add_point_10 = false
    add_point_11 = false add_point_12 = false add_point_13 = false add_point_14 = false add_point_15 = false add_point_16 = false add_point_17 = false add_point_18 = false add_point_19 = false add_point_20 = false
    add_point_21 = false add_point_22 = false add_point_23 = false add_point_24 = false add_point_25 = false add_point_26 = false add_point_27 = false add_point_28 = false add_point_29 = false add_point_30 = false
    add_point_31 = false add_point_32 = false
  end

Any way to do this with tables?

Thanks!

-- creating a table for the example.
local points = {
  add_point_1 = true, add_point_2 = true, add_point_3 = true,
  add_point_4 = true, add_point_5 = true, add_point_6 = true,
  add_point_7 = true, add_point_8 = true, add_point_9 = true,
  add_point_10 = true, add_point_11 = true, add_point_12 = true,
  add_point_13 = true, add_point_14 = true, add_point_15 = true,
  add_point_16 = true, add_point_17 = true, add_point_18 = true,
  add_point_19 = true, add_point_20 = true, add_point_21 = true,
  add_point_22 = true, add_point_23 = true, add_point_24 = true,
  add_point_25 = true, add_point_26 = true, add_point_27 = true,
  add_point_28 = true, add_point_29 = true, add_point_30 = true,
  add_point_31 = true, add_point_32 = true
}

-- set all values to something
function set_all_values(tbl, value)
  for k, _ in pairs(tbl) do
    tbl[k] = value
  end
end

function set_active_point(point)
  if (point == 0) then
    set_all_values(points, true)
  elseif (point == 32) then
    set_all_values(points, false)
  else
    set_all_values(points, true)
    points["add_point_" .. point] = false
  end 
   
end

set_active_point(1)

PS.

Alternate approach: In a well structured code, you migh want to make a “point” class - as a nice “package” of all values, behaviors and data (like gui) of a point. All these point objects could then have a value that is “connected” to a single renoise.Document.ObservableBoolean object. In practice, you will then be able to automatically set all point values by setting a single global value.

This is a bit complex to explain in a short post, but I just want to mention it to give a vague idea of how things “should” be done ideally.

-- creating a table for the example.
local points = {
add_point_1 = true, add_point_2 = true, add_point_3 = true,
add_point_4 = true, add_point_5 = true, add_point_6 = true,
add_point_7 = true, add_point_8 = true, add_point_9 = true,
add_point_10 = true, add_point_11 = true, add_point_12 = true,
add_point_13 = true, add_point_14 = true, add_point_15 = true,
add_point_16 = true, add_point_17 = true, add_point_18 = true,
add_point_19 = true, add_point_20 = true, add_point_21 = true,
add_point_22 = true, add_point_23 = true, add_point_24 = true,
add_point_25 = true, add_point_26 = true, add_point_27 = true,
add_point_28 = true, add_point_29 = true, add_point_30 = true,
add_point_31 = true, add_point_32 = true
}

-- set all values to something
function set_all_values(tbl, value)
for k, _ in pairs(tbl) do
tbl[k] = value
end
end

function set_active_point(point)
if (point == 0) then
set_all_values(points, true)
elseif (point == 32) then
set_all_values(points, false)
else
set_all_values(points, true)
points["add_point_" .. point] = false
end 
   
end

set_active_point(1)

PS.

Alternate approach: In a well structured code, you migh want to make a “point” class - as a nice “package” of all values, behaviors and data (like gui) of a point. All these point objects could then have a value that is “connected” to a single renoise.Document.ObservableBoolean object. In practice, you will then be able to automatically set all point values by setting a single global value.

This is a bit complex to explain in a short post, but I just want to mention it to give a vague idea of how things “should” be done ideally.

Thanks Joule!

Solved!

Finally I have chosen to include better structured tables to have access to several true or false at the same time.In this way I can, for example, change to true the even numbers, or the odd numbers, or all at once, or in a chain.I also use other tables to access several multi-button properties.So I can call all of them using a single number.

For example:

--show points variable
show_point = { false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
               false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }
---
function vpd_aut_show_point(value)
  if ( show_or_chain == false ) then
    if ( show_point[value] == false ) then
      show_point[value] = true
      vb.views["VPD_AUT_CONTROLS_"..value].visible = true
      vb.views["VPD_AUT_BT_POINT_"..value].color = VPD_AUT_PNT_CLR_ON[value]
      vb.views["VPD_AUT_POINT_"..value].visible = true
    else
      show_point[value] = false
      vb.views["VPD_AUT_CONTROLS_"..value].visible = false
      vb.views["VPD_AUT_BT_POINT_"..value].color = VPD_AUT_PNT_CLR_OFF[value]
      vb.views["VPD_AUT_POINT_"..value].visible = false
    end
  else
    for i = 1, 32 do
      if ( i > value ) then
        show_point[i] = false
        vb.views["VPD_AUT_CONTROLS_"..i].visible = false
        vb.views["VPD_AUT_BT_POINT_"..i].color = VPD_AUT_PNT_CLR_OFF[i]
        vb.views["VPD_AUT_POINT_"..i].visible = false
      else
        show_point[i] = true
        vb.views["VPD_AUT_CONTROLS_"..i].visible = true
        vb.views["VPD_AUT_BT_POINT_"..i].color = VPD_AUT_PNT_CLR_ON[i]
        vb.views["VPD_AUT_POINT_"..i].visible = true
      end 
    end  
  end
end

--and a button for bang!
vb:button {
  id = "VPD_AUT_BT_POINT_1",
  height = 20, width = 28,
  color = VPD_AUT_PNT_CLR_OFF[1],
  text = "1",
  notifier = function() vpd_aut_show_point(1) end
},