bad argument #2 to 'newSource' (string expected, got no value)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
lushfoliage
Prole
Posts: 5
Joined: Mon May 18, 2020 4:40 pm

bad argument #2 to 'newSource' (string expected, got no value)

Post by lushfoliage »

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:

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')
    }
StartState where it's used

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
and the sound file is just a paddle_hit.wav in a sounds folder. Any idea what I've messed up?
MrFariator
Party member
Posts: 512
Joined: Wed Oct 05, 2016 11:53 am

Re: bad argument #2 to 'newSource' (string expected, got no value)

Post by MrFariator »

In the past, love.audio.newSource allowed the second parameter, type, to be optionally omitted, and default to "stream". Nowdays you have to specify the type of the source, so all you need to do is

Code: Select all

gSounds = {
  ['paddle-hit'] = love.audio.newSource('sounds/paddle_hit.wav', 'static')
  -- or
  ['paddle-hit'] = love.audio.newSource('sounds/paddle_hit.wav', 'stream')
  -- ... the rest
 }
For sound effects, it's probably preferable to use 'static'.
lushfoliage
Prole
Posts: 5
Joined: Mon May 18, 2020 4:40 pm

Re: bad argument #2 to 'newSource' (string expected, got no value)

Post by lushfoliage »

thank you!
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: bad argument #2 to 'newSource' (string expected, got no value)

Post by zorg »

Also, because you will most probably run into it, 11.3 uses the 0-1 color range now instead of what the 0.10.something version most CS50 courses use, which used the 0-255 range... contemplation regarding a pinned post stating all this to people coming from the harvard CS50 course rising, although ultimately it might be pointless.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 117 guests