srssmith92 Lv 1
I have a puzzle where I run the following test script. The puzzle is #322.
Half way through the list of deleting the bands I get the following error:
bad argument #1 to 'band_delete' (band index out of range)
In my most recent example, 25 of 51 are deleted. Failure on 26. Curious that this is half of the total.
I don't see how this can be. Foldit API gave the script the count and then the script runs through
that count.
– band create delete test
function create_a_band(start,finish)
band_add_segment_segment(start,finish)
end
function draw_bands(seg_list)
for i=1,#seg_list do
create_a_band(seg_list[i].start,seg_list[i].finish)
end
end
function create_seg_pairs(beg_seg, end_seg, stride)
local seg_list = {}
for i = beg_seg, end_seg do
local seg_pair = {}
seg_pair.start = i
seg_pair.finish = i + stride
seg_list[#seg_list+1] = seg_pair
end
return seg_list end
function delete_all_bands()
local band_count = get_band_count()
local loop
for loop = 1, band_count do
print("deleting band ", loop, " of ", band_count)
band_delete(loop)
end
end
seg_list = {}
g_segments = get_segment_count()
stride = 3
seg_list = create_seg_pairs(2,g_segments-stride-5,stride)
draw_bands(seg_list)
delete_all_bands()