Help?

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

Help?

Post by miz656 »

function love.load()
local s = love.audio.newSource("TOTE_iT.mp3","static")
s:setVolume(0.9)
s:setPitch(0.9)
love.audio.play(s)
end
function love.update()
if key == "9" then
for i = 1,9 do
wait(1)
text = i +1
end
end
end
function love.quit()
pcall(function() print("Goodbye!")
end)
end

Doesn't show text when I press 9. Help?
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Help?

Post by miko »

miz656 wrote: Doesn't show text when I press 9. Help?
And why you have assumed it should? What and where sets the value of key? Try either keyboard.isDown() of love.keypressed()/love.keyreleased(), without it there is no way to tell what key was pressed. And no, there is no wait(). Even if there was, you should not use it like that, or your game will freeze. Remember that your love.draw() function should be called about 60 times per second, and it will not be called until love.update() has finished. You should use (dt) from love.update(dt) to increment you accumulator, and then make your changes after passing a threshold.
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
miz656
Prole
Posts: 20
Joined: Fri Nov 25, 2011 3:39 pm

Re: Help?

Post by miz656 »

So you mea

love.keyreleased(9)

?

I'm learning these objects...
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Help?

Post by Ellohir »

http://love2d.org/wiki/love.keypressed

http://love2d.org/wiki/love.keyboard.isDown

You should really look into the wiki your doubts instead of asking every time. The wiki has the solution to use love commands 90% of the time.
User avatar
miko
Party member
Posts: 410
Joined: Fri Nov 26, 2010 2:25 pm
Location: PL

Re: Help?

Post by miko »

miz656 wrote:So you mea

love.keyreleased(9)

?

I'm learning these objects...
Have you read the documentation for love.keypressed / love.keyreleased ? It should read:

Code: Select all

function love.keypressed(key, unicode)
  if key=="9" then
    ...
  end
end
My lovely code lives at GitHub: http://github.com/miko/Love2d-samples
miz656
Prole
Posts: 20
Joined: Fri Nov 25, 2011 3:39 pm

Re: Help?

Post by miz656 »

Nothing happened. When I pressed 9 the text didn't come...Is the text black because everything is black on my screen and maybe that'swhy...
User avatar
Ellohir
Party member
Posts: 235
Joined: Sat Oct 22, 2011 11:12 pm

Re: Help?

Post by Ellohir »

That's it, you have to change the text color with "love.graphics.setColor(255,255,255)" to white, well thought :awesome:
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Help?

Post by Robin »

The text color is white by default...
Help us help you: attach a .love.
LuaWeaver
Party member
Posts: 183
Joined: Wed Mar 02, 2011 11:15 pm
Location: Ohio, USA

Re: Help?

Post by LuaWeaver »

You have no love.draw(). This is the problem. :monocle:

Edit: Or variable called text. :monocle:

example:

Code: Select all

function love.load()
text=""
end

function love.keypressed(key)
if key=="9" then
for i=1, 9 do
text=text..i --If you just used text=i, then it would come out just 9. This adds i to the string, instead.
end
end
end

function love.draw()
love.graphics.print(text, love.graphics.getWidth()/2, love.graphics.getHeight()/2)
end
"your actions cause me to infer your ego is the size of three houses" -finley
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 12 guests