I've gotten the menu to automatically add buttons for new levels added to the songlist file, but whenever I try to enter a level, it plays a distorted version of one specific song, no matter what level I choose. Obviously, each level is supposed to have it's own song, so it should be playing a non-distorted version of each level's respective song. I'm pretty sure it's reading the json file incorrectly, but I barely have any idea what exactly is going wrong.
This is the main section of the code that I think is the problem:
Code: Select all
function danzsongs.enter()
buttons = {}
for i,k in ipairs(songList) do
songFile = json.decode(love.filesystem.read(k["Song"]))
for j,l in ipairs(songFile) do
buttonTitle = l["songName"]
songlevel = l["songWav"]
songBPM = l["songBPM"]
songOffset = l["songOffset"]
end
table.insert(buttons, newButton(
buttonTitle,
function()
print("Starting game")
love.audio.stop()
Gamestate.switch(levelface)
songlevel = songlevel
songBPM = songBPM
songCrochet = 60 / songBPM
songOffset = songOffset
end))
end
table.insert(buttons, newButton(
"Back",
function()
love.audio.stop( )
Gamestate.switch(menu)
end))
end
function levelface.draw()
buttons = {}
love.graphics.setColor(0.9, 0.8, 0.85, 1.0)
local tracker = {50, 400, 75, 550, 750, 550, 750, 400}
love.graphics.polygon('line', tracker)
levelsong = love.audio.newSource(songlevel, "stream")
love.audio.play(levelsong)
songPosition = levelsong:tell("seconds")
love.graphics.print(
songPosition,
font,
10,
10
)
end
EDIT: Uploaded the source code to Github in case people don't want to bother downloading
https://github.com/RAYTRAC3R/DANZ/
EDIT 2: Managed to fix the distortion with help from a user in the Discord, I accidentally set the song source under levelface.draw() rather than levelface.enter()
It still seems to play the wrong song. It always plays the last song in the songlist file.