Lua math.random problem

So, we start with self.last_pos == 100, so let’s figure out what values of random_x get us out of the loop.

  • self.last_pos >= random_x - 100 is false when random_x >= 201
  • self.last_pos <= random_x + 100 is false when random_x < 0

Since random_x can’t be less than 50, it will never be less than 0, so your while loop will never exit.

2 Likes