bad argument #2 to 'newSource' (string expected, got no value)
Posted: Mon May 18, 2020 5:37 pm
Hello, I've been taking Harvard's free game design course so I'm not particularly well-versed with lua or Love2D. When creating a global table for all of my sounds, I received this error:
bad argument #2 to 'newSource' (string expected, get no value)
I went as far as to copy and paste the code found in the course's GitHub link for the main.lua file, but I received the same error. When I hover over the gSounds in my code, each of the keys(?) shows a ['name']: any, excluding ['paddle-hit']: table, which sometimes is a ['paddle-hit']: boolean instead.
I'm only in breakout-0
https://github.com/games50/breakout/tre ... /breakout0
gSounds table:
StartState where it's used
and the sound file is just a paddle_hit.wav in a sounds folder. Any idea what I've messed up?
bad argument #2 to 'newSource' (string expected, get no value)
I went as far as to copy and paste the code found in the course's GitHub link for the main.lua file, but I received the same error. When I hover over the gSounds in my code, each of the keys(?) shows a ['name']: any, excluding ['paddle-hit']: table, which sometimes is a ['paddle-hit']: boolean instead.
I'm only in breakout-0
https://github.com/games50/breakout/tre ... /breakout0
gSounds table:
Code: Select all
gSounds = {
['paddle-hit'] = love.audio.newSource('sounds/paddle_hit.wav'),
['score'] = love.audio.newSource('sounds/score.wav'),
['wall-hit'] = love.audio.newSource('sounds/wall_hit.wav'),
['confirm'] = love.audio.newSource('sounds/confirm.wav'),
['select'] = love.audio.newSource('sounds/select.wav'),
['no-select'] = love.audio.newSource('sounds/no_select.wav'),
['brick-hit-1'] = love.audio.newSource('sounds/brick-hit-1.wav'),
['brick-hit-2'] = love.audio.newSource('sounds/brick-hit-2.wav'),
['hurt'] = love.audio.newSource('sounds/hurt.wav'),
['victory'] = love.audio.newSource('sounds/victory.wav'),
['recover'] = love.audio.newSource('sounds/recover.wav'),
['high-score'] = love.audio.newSource('sounds/high_score.wav'),
['pause'] = love.audio.newSource('sounds/pause.wav'),
['music'] = love.audio.newSource('sounds/music.wav')
}
Code: Select all
local highlighted = 1
function StartState:update(dt)
-- toggle highlighted option if we press an arrow key up or down
if love.keyboard.wasPressed('up') or love.keyboard.wasPressed('down') then
highlighted = highlighted == 1 and 2 or 1
gSounds['paddle-hit']:play()
end
-- we no longer have this globally, so include here
if love.keyboard.wasPressed('escape') then
love.event.quit()
end
end