Different Timer with different start times

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
thep6
Prole
Posts: 1
Joined: Sat Jun 07, 2014 2:10 pm

Different Timer with different start times

Post by thep6 »

Hello

I'm pretty new to LÖVE and lua. I know the love.timer.getTime() command but I'm trieng to build my own League of Legends Jungletimer, that counts down from 5:00 minutes and stops at 0:00.

I looked up, how to do a simple Timer that ticks down.

Code: Select all

function timerdownblueb()

bluebtimer = true
		local currentTime = love.timer.getTime()
		local timeDelta = math.floor(currentTime - initTime ) -- initTime is a variable loaded in love.load()
			currentNumbersecbb = 59 - timeDelta -- let's the second tick down
			currentNumberminbb = 4 
		if currentNumbersecbb < 1 and currentNumberminbb < 1 then -- checks, if the countdown is 0:00 and stops displaying the timer with bluebtimer =false
			bluebtimer = false
			
		elseif currentNumbersecbb < 1 then    -- this is to let minutes tick down and let the seconds start again
		currentNumberminbb = currentNumberminbb - 1
		currentNumbersecbb = 59- timeDelta -- I tried to let the seconds start over again here.. but it doesn't seem to work...
			end
		
			
end
I start it with a keyboard.isDown() command, because i couldn't find a way to start it with a mouseclick and right now, it only shows the downticking while pressing the button.

I copied this with different variables for the other jungle buffs in league of legends and wanted to start it with a different Button.
My problem now is that if i start a countdown, the other countdown won't start at 5:00 but at the same time the other countdown is right now. for an example: if one timer is at 4:30 and i start another timer it starts at 4:30 and not 5:00

Ok, what im asking now is, if someone could help me and show me a way to have more than one resetable countdown that will reset itself after its duration and is startable again afterwards. And maybe even a way to programm clickable areas.

I can give you a .love file too, if it's needed.

Thank you very much in advance
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: Different Timer with different start times

Post by artofwork »

I know this is an old thread but it still should be answered because its important :)


When you write a function in any language the function should be 100% generic, meaning all the values within the function should have a scope of local to that function. This way you can reuse the function over and over for different values passed to it.

I made some minor changes to your code but its 99.9% all yours :)

You can make whatever changes to make it work as needed as i didn't correct anything and didn't want to confuse you further.
timer.PNG

Code: Select all

function love.load()
initTime = love.timer.getTime()
end

function love.update()end

function love.draw()
	timerdownblueb(initTime, 0, 0)
	timerdownblueb(initTime+50, 0, 100)
end


function timerdownblueb(startTime, x, y)
	local bluebtimer = true
    local currentTime = love.timer.getTime()
    local timeDelta = math.floor(currentTime - startTime) 
    local currentNumbersecbb = 59 - timeDelta -- let's the second tick down
    local currentNumberminbb = 4 
	-- checks, if the countdown is 0:00 and stops displaying the timer with bluebtimer =false
    if currentNumbersecbb < 1 and currentNumberminbb < 1 then 
		bluebtimer = false
    elseif currentNumbersecbb < 1 then    -- this is to let minutes tick down and let the seconds start again
		currentNumberminbb = currentNumberminbb - 1
		currentNumbersecbb = 59- timeDelta -- I tried to let the seconds start over again here.. but it doesn't seem to work...
    end  
	love.graphics.setColor(255,255,255)
	love.graphics.print("current Number sec bb "..currentNumbersecbb, x, y)
	love.graphics.print("current Number min bb "..currentNumberminbb, x, y+30)
end
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests