Timer

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
GloriousDerp
Prole
Posts: 6
Joined: Tue Feb 25, 2014 10:52 pm

Timer

Post by GloriousDerp »

I am trying to make an object move randomly. I made a random number generator and want to set a timer to make the number generator generate a number every 1 or 2 seconds. I have it so when i push a key it will generate a number right now. Help?

Code: Select all

	--elseif love.keyboard.isDown("i") then
		--rand = math.random(1, 4)
	end
	
	if rand == 1 then
		objects.box2.body:applyForce(500, 0 )
	elseif rand == 2 then
		objects.box2.body:applyForce(-500,0)
	elseif rand == 3 then
		objects.box2.body:applyForce(0, 500)
	elseif rand == 4 then
		objects.box2.body:applyForce(0, -500)
	end
		
User avatar
IceQB
Citizen
Posts: 67
Joined: Sat Nov 03, 2012 1:11 pm

Re: Timer

Post by IceQB »

You can make it like that

Code: Select all

seconds = 0
timerun = 1 
function update_fps(dt)
baseTimer = baseTimer + dt
if baseTimer > 1 then
  baseTimer = baseTimer - 1
 seconds = seconds + timerun
end

if seconds > 2 then
seconds = 0
end
if seconds >=2 then
rand = math.random(1, 4)
end
end
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 5 guests