Error while trying to play a .Wav file

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
BuddhaRandom
Prole
Posts: 3
Joined: Sun Feb 23, 2020 4:18 am

Error while trying to play a .Wav file

Post by BuddhaRandom »

New here, new to Lua. I've been following along with a tutorial and whilst now near the end I have hit a snag. The following code produces an error:

Code: Select all

local music
local volume

function love.load()
    music = love.audio.newSource("Randomize10.wav")
    music:play()
end
Gives me the following error:

Code: Select all

Error
main.lua:15: bad argument #2 to 'newSource' (string expected, got no value)

Traceback

[C]: in function 'newSource'
main.lua:15: in function 'load'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
I don't understand what the issue is; this is similar to other examples I've found which I've tried and get the same error. The .wav file is in the same directory as my code. Do I need to explicitly define the path? I've not needed to with sprites, perhaps audio is different.

Edit: The file name is the same Case as well.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: Error while trying to play a .Wav file

Post by raidho36 »

The error text spells it out for you: the function expects string as a 2nd argument, and you gave it nothing.
BuddhaRandom
Prole
Posts: 3
Joined: Sun Feb 23, 2020 4:18 am

Re: Error while trying to play a .Wav file

Post by BuddhaRandom »

What string is it expecting? Something like "static" perhaps? Isn't the path name a string? Or is it looking for someting additional?

This seems work fine in the tutorial video. He gets no error when running the same code. There is also code very simular in the documentation and while it does not work for me, it seems to have worked for others. Maybe something has changed since then?
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: Error while trying to play a .Wav file

Post by MrFariator »

I don't know what video tutorial you are watching, or what version of LÖVE it is for, but looking at the wiki suggests to me that in versions prior to 11.0 the second parameter to love.audio.newSource was optional. In such versions, this parameter defaulted to "stream", while in 11.0 and onwards you need need to explicitly define it. If you click on "SourceType" on that wiki page, it will show you this page, which lists what strings the function accepts.

As such, to troubleshoot the errors you are encountering either downgrade to the same version of LÖVE the video tutorial is using, or look at the wiki for the up-to-date version of the LÖVE API.
BuddhaRandom
Prole
Posts: 3
Joined: Sun Feb 23, 2020 4:18 am

Re: Error while trying to play a .Wav file

Post by BuddhaRandom »

The tuturial is from 2016 so no doubt there's been changes, I didn't check the date till just now. I was looking at exampels in the wiki, particularly here at the bottom there are examples with and without strings, so I got confused thinking my code should run.

Thanks so much for the assistance and the links; appreciate you.
MrFariator
Party member
Posts: 548
Joined: Wed Oct 05, 2016 11:53 am

Re: Error while trying to play a .Wav file

Post by MrFariator »

The wiki unfortunately has some outdated pages; the tutorial pages in particular. As such I'd usually look at the pages for individual functions and such, or module pages which often have a table with "+" or "-" icons denoting when certain functions have been added or deprecated. As a last resort, you can check the version history too in some fringe cases, particularly when a new version has just released.

If you ever want to run examples or pieces of code intended for a specific version you can always use Polyamory.
Post Reply

Who is online

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