while statement freezes the game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
notcl4y
Citizen
Posts: 85
Joined: Fri Nov 25, 2022 12:23 pm

while statement freezes the game

Post by notcl4y »

How do I fix that? I'm trying to separate the player and the floor when they collide.

Code: Select all

function Player:updatePhysics(dt)
  if self.collider:collides(floor) then
    while self.collider:collides(floor) do
      self.y = self.y - 1 * dt
      print(self.y, self.collider:collides(floor))
    end
    self.velY = 0
    self.onFloor = true
  else
    self.velY = self.velY + 0.5
    self.onFloor = false
  end
  
  self.x = self.x + self.velX
  self.y = self.y + self.velY
end

Code: Select all

loves_lua = "not so",
wants_to = true
User avatar
zalander
Citizen
Posts: 72
Joined: Mon Jan 09, 2023 5:58 am
Location: India

Re: while statement freezes the game

Post by zalander »

I think you should try adding a love.timer.sleep(0.1) in the loop as the loop can run very fast (thanks to modern computers) and freeze the game so it should help i think

Code: Select all

while true do
	love.timer.sleep(0.1)
	-- do stuff
end
Using LOVE to make everything except games :crazy:

Code: Select all

astring = "pog"
print(astring)
--pog
User avatar
notcl4y
Citizen
Posts: 85
Joined: Fri Nov 25, 2022 12:23 pm

Re: while statement freezes the game

Post by notcl4y »

zalander wrote: Sat Jun 10, 2023 5:14 pm I think you should try adding a love.timer.sleep(0.1) in the loop as the loop can run very fast (thanks to modern computers) and freeze the game so it should help i think

Code: Select all

while true do
	love.timer.sleep(0.1)
	-- do stuff
end
It still doesn't work. According to print(self.y, self.collider:collides(floor)) it says that...Oh, wait. The collider's position just doesn't get updated! Now it works. Thanks anyways!

Code: Select all

loves_lua = "not so",
wants_to = true
Post Reply

Who is online

Users browsing this forum: No registered users and 59 guests