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
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?