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
New, can someone fix this?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- rhezalouis
- Party member
- Posts: 100
- Joined: Mon Dec 07, 2009 10:27 am
- Location: Indonesia
- Contact:
Re: New, can someone fix this?
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.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 :
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".
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) --
Code: Select all
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...
Re: New, can someone fix this?
I thought it was only used to set variables?
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: New, can someone fix this?
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.
Who is online
Users browsing this forum: Bing [Bot] and 5 guests