I have a table for each button that includes the value of its pitch (e.g 1, 1.25, 1.42, etc.) and I use a FOR loop to get the Pitch value from the table. However, it's only giving me the first button's pitch value.
Code: Select all
buttons = {
{
{["state"]=3, ["posX"]=16, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=56, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=96, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=136, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=176, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=216, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=256, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=296, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=336, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=376, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=416, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=456, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=496, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=536, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=576, ["posY"]=16, ["pitch"]=4},
{["state"]=3, ["posX"]=616, ["posY"]=16, ["pitch"]=4}
},
... etc etc
Code: Select all
function getBtnPitch()
for k in pairs(buttons) do
for l in pairs(buttons[k]) do
return buttons[k][l].pitch;
end
end
end
function playTone(pitch)
source:setPitch(pitch);
love.audio.play(source);
end
here's the function that calls the getBtnPitch():
Code: Select all
-- Get Active Notes
for a in pairs(buttons) do
for b in pairs(buttons[a]) do
if (header.posX == buttons[a][b].posX) then
if (buttons[a][b].state == 1) then
buttons[a][b].state = 2;
getBtnNote();
pitch = getBtnPitch();
playTone(pitch);
end
else
if (buttons[a][b].state == 2) then
buttons[a][b].state = 1;
end
end
end
end
Updated for 11.2