Page 1 of 1
Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 4:31 am
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.
Re: Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 7:00 am
by raidho36
The error text spells it out for you: the function expects string as a 2nd argument, and you gave it nothing.
Re: Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 5:42 pm
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?
Re: Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 6:03 pm
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.
Re: Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 7:22 pm
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.
Re: Error while trying to play a .Wav file
Posted: Sun Feb 23, 2020 8:31 pm
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.