My time not printing to the screen but is working with print

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
MrMonacle
Prole
Posts: 8
Joined: Mon Jan 21, 2013 11:57 pm

My time not printing to the screen but is working with print

Post by MrMonacle »

I have run into a problem when working on my game. I need a timer and it doesn't seem to be working. When I use

Code: Select all

print(timer)
it works but when in love.draw() with this code

Code: Select all

love.graphics.print(timer)
it gives me the error, "Error, main.lua.18: bad argument #1 to 'print' (string expected, got nil)". If anyone has anything that could help me, that would be awesome.
n1ghtk1n9
Prole
Posts: 10
Joined: Sat Dec 22, 2012 12:23 am

Re: My time not printing to the screen but is working with p

Post by n1ghtk1n9 »

You're missing a few variables, you're not defining where on the screen you want to print that, and you must not have defined what timer is, because it is say it is "nil", or nothing

To print it correctly, you should do love.graphics.print(timer, 256, 512)

The 256 and 512 are the X and Y coordinates, they can be anything you want (inside of the screen's Width and Height, of course)

Also, please provide the .love of your game
MrMonacle
Prole
Posts: 8
Joined: Mon Jan 21, 2013 11:57 pm

Re: My time not printing to the screen but is working with p

Post by MrMonacle »

I will try that. If it doesn't work, I will post the .love

EDIT: Just didn't define the location, that worked.
MrMonacle
Prole
Posts: 8
Joined: Mon Jan 21, 2013 11:57 pm

Re: My time not printing to the screen but is working with p

Post by MrMonacle »

One more question, when my timer hits, 14.5, I have it set to 0 and then start again but I want it to keep going up to 14.5 and then going back to 0 and starting again, any help? I currently have this code

Code: Select all

function love.update(dt)
timer = love.timer.getTime()



if timer >= 14.5 then
timer = 0
end

if timer <= 0 then
timer = love.timer.getTime()-14.5
end


end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: My time not printing to the screen but is working with p

Post by Robin »

You want to go up and down, up and down?

You need another variable, to keep track of direction.

Code: Select all

function love.load()
    timer = 0
    goingup = true
    MAX_TIMER = 14.5
end

function love.update(dt)
    if goingup then
        timer = timer + dt
        if timer >= MAX_TIMER then
            timer = MAX_TIMER
            goingup = false
        end
    else
        timer = timer - dt
        if timer <= 0 then
            timer = 0
            goingup = true
        end
    end
-- ...
end

Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 6 guests