Error

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
Mridul121561
Prole
Posts: 1
Joined: Wed Mar 16, 2022 8:39 am

Error

Post by Mridul121561 »

Okay so here's the code:

Code: Select all

function love.load()
player = {}
player.x = 400
player.y = 400
player.speed = 3
block = {}
block.x = math.random(00, 200)
block.y = math.random(00, 200)
block.speed = math.random(100, 200)
player.radius = 25
end
function love.update(dt)
  if love.keyboard.isDown("w") then
    player.y = player.y - player.speed
  end
  if love.keyboard.isDown("s") then
    player.y = player.y + player.speed
  end
  if love.keyboard.isDown("a") then
    player.x = player.x - player.speed
  end
  if love.keyboard.isDown("d") then
    player.x = player.x + player.speed
  end

  block.y = math.random(0, 800) + 1
  block.x = math.random(0, 600) + 1
  if distanceBetween (block.x, block.y, 5, 5) >= 50 then
    block.y = math.random(5, 800)
  end
  if distanceBetween (block.x, block.y, 600, 5) >= 50 then
    block.y = math.random(5, 800)
  end
  if distanceBetween (block.x, block.y, 5, 800) >= 50 then
    block.y = math.random(5, 800)
  end
  if distanceBetween (block.x, block.y,600, 800) >= 50 then
    block.y = math.random(5, 800)
  end
  if distanceBetween (block.x. block.y, player.x, player.y) >= player.radius then
  end
end

function love.draw()
  love.graphics.circle("fill", player.x, player.y, player.radius)
  love.graphics.rectangle("fill", block.x, block.y, 50,50)
end

function distanceBetween(x1, y1, x2, y2)
  return math.sqrt((x2 - x1)^2 + (y2 - y1)^2)
end

And it is giving me this error:
Error

main.lua:40: attempt to index field 'x' (a number value)


Traceback

[love "callbacks.lua"]:228: in function 'handler'
main.lua:40: in function 'update'
[love "callbacks.lua"]:162: in function <[love "callbacks.lua"]:144> Um.. what??
[C]: in function 'xpcall'
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: Error

Post by veethree »

There's a dot instead of a comma after the first argument of distanceBetween call on line 40.
Post Reply

Who is online

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