Looping over a "range" of number keys in a dictionary, instead of the whole thing

I’m making a rhythm game, and currently have a dictionary pointing out the beat and note information of certain “rows” of notes.

local testmap = {
	b = 140,
	id = 5769783133,
	
	notes ={ 
		[4.0] = { --4th beat.
			n = {'_','h','_','h'}, --note information, h represents a single note, the index represents the arrow it is on. (this is a four key thing.)
		},
		[8.0] = { --8th beat.
			n = {'h','_','h','_'}, --left, up. '_' means there is no note.
		},
	}
}

Every RenderStepped, I want to loop over the whole note dictionary.

function renderNotes() --this function is connected to RenderStepped.
	local function rowRender(key,value)
		local noteInfo = value['n']
		if noteInfo then
			print(noteInfo) --simplified
		end
	end

	for key,value in pairs(testmap['notes']) do
		rowRender(key,value)
	end
end

However, with very large maps, i don’t want to be rendering every single note every RenderStepped. This is the only decent solution I’ve thought up so far, that would include thirds and every kind of note (eights, fourths, sixteenths, etc…). But it’s still looping for every beat, even if it’s returning.

local range = 32
function renderNotes()
	local function rowRender(key,value)
		local noteInfo = value['n']
		if noteInfo then
			print(noteInfo)
		end
	end

	for key,value in pairs(testmap['notes']) do
		if key-_G.beat > range then return end --_G.beat represents the current beat of the song.
		rowRender(key,value)
	end
end

And here’s the solution that I would want to work, but doesn’t :frowning:

	for key+_G.beat,value in pairs(testmap['notes']) do
		rowRender(key,value)
	end

And here’s a bad solution, that unfortunately doesn’t work with thirds and very tight notes (like 1/256ths). It also results in a lot of unnecessary looping.

local range = 256
for count = -10, range,0.0625 do
	local key = _G.beat+count
	value = testmap['notes'][key]
	if value then
		print(value)
	end
end

Can anyone help me out here?

For some reason only making this post has made me think of a solution… You have to use sections.

local testmap = {
	b = 140,
	id = 5769783133,
	sections = { --8 beats allowed for each section
		[1.0] = { --section one
			notes ={ 
				[4] = {
					n = {'h','_','_','h'},
					s = {1},
					b = 140,
				},
				[15/3] = {
					n = {'_','h','h','_'},
					s = {2},
				},
				[8] = {
					n = {'h','_','_','h'},
					s = {1},
				},
			},
		},
		[2.0] = { --section two
			notes ={ 
				[12] = {
					n = {'h','_','h','_'},
					s = {4},
				},
				[14] = {
					n = {'_','h','_','h'},
					s = {3},
				},
				[16] = {
					n = {'h','_','h','_'},
					s = {2},
				},
			},
		}
	}
}