Page 1 of 1

New, can someone fix this?

Posted: Sat Nov 26, 2011 4:54 pm
by miz656
function love.load()
local s = love.Audio.newSource("TOTE_iT.mp3","static")
end
s:setVolume(0.9)
s:setPitch(0.9)
love.Audio.Play(s)
function love.update()
if key.mousepressed == "9" then
for i = 1,9 do
text = i +1
end
end
end
function love.quit()
pcall(function() print("Goodbye!")
end)
end

Output
Attempt to index global s (a nil value)

I really don't know the sound of love 0=0

Re: New, can someone fix this?

Posted: Sat Nov 26, 2011 5:45 pm
by rhezalouis
Hi miz656,

Anything you put directly in the main.lua (i.e. outside any functions) would be interpreted as soon as löve load that file (cmiiw). Your source s is initiated in the love.load() so you could only work on that variable after that initiation i.e e.g. in love.load() after that line.

Code: Select all

function love.load()
  local s = love.Audio.newSource("TOTE_iT.mp3","static")
  s:setVolume(0.9)    --they should be here
  s:setPitch(0.9)     --
  love.Audio.Play(s)  --
end
--don't put these lines outside the function where s was first defined
--s:setVolume(0.9)    --wrong position
--s:setPitch(0.9)     --
--love.Audio.Play(s)  --
Btw, what do you want to do in that love.update? I add some simple functions and introduce closure (or, cmiiw, in short: accessing the localised s using a function defined in the same block) here :P :
[miz656]PitchingSound.love
LÖVE 0.7.2
(3.73 KiB) Downloaded 117 times
N.B. Please encase your code using the "" tag.
N.B. If you localised the s, you can't access it outside the block; and don't forget that Lua is case-sensitive: "love.Audio" is not the same with "love.audio".

Re: New, can someone fix this?

Posted: Sat Nov 26, 2011 5:50 pm
by miz656
I thought it was only used to set variables?

Re: New, can someone fix this?

Posted: Sun Nov 27, 2011 11:34 am
by Robin
No, love.load() can be used for all preparations you need to do before the game starts: loading resources, building maps, setting up fonts and graphics modes, ...