Page 1 of 1

Help?

Posted: Sat Nov 26, 2011 10:15 pm
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?

Re: Help?

Posted: Sat Nov 26, 2011 10:49 pm
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.

Re: Help?

Posted: Sat Nov 26, 2011 10:53 pm
by miz656
So you mea

love.keyreleased(9)

?

I'm learning these objects...

Re: Help?

Posted: Sat Nov 26, 2011 11:31 pm
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.

Re: Help?

Posted: Sat Nov 26, 2011 11:31 pm
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

Re: Help?

Posted: Sun Nov 27, 2011 2:36 am
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...

Re: Help?

Posted: Sun Nov 27, 2011 12:08 pm
by Ellohir
That's it, you have to change the text color with "love.graphics.setColor(255,255,255)" to white, well thought :awesome:

Re: Help?

Posted: Sun Nov 27, 2011 12:17 pm
by Robin
The text color is white by default...

Re: Help?

Posted: Mon Nov 28, 2011 2:02 am
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