New, can someone fix this?

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
miz656
Prole
Posts: 20
Joined: Fri Nov 25, 2011 3:39 pm

New, can someone fix this?

Post 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
User avatar
rhezalouis
Party member
Posts: 100
Joined: Mon Dec 07, 2009 10:27 am
Location: Indonesia
Contact:

Re: New, can someone fix this?

Post 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 118 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".
Aargh, I am wasting my posts! My citizenshiiiip... :o
miz656
Prole
Posts: 20
Joined: Fri Nov 25, 2011 3:39 pm

Re: New, can someone fix this?

Post by miz656 »

I thought it was only used to set variables?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: New, can someone fix this?

Post 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, ...
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 9 guests