HardonCollider Collision 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
Jackim
Prole
Posts: 12
Joined: Wed Apr 03, 2013 3:02 am
Location: Canada

HardonCollider Collision Error

Post by Jackim »

I'm trying to get simple collisions working, and I'm getting an error when two object collide.

My error is as follows:

Code: Select all

hardoncollider/polygon.lua:265: attempt to index local 'dx' (a nil value)

Traceback

hardoncollider/polygon.lua:265:in function 'move'
hardoncollider/shapes.lua:327: in function 'old_func'
hardoncollider/init.lua:104: in function 'move'
main.lua:8: in function 'on_collide'
hardoncollider/init.lua:196: in function 'update'
main.lua:36: in function 'update'
[C]: in function 'xpcall'

Code: Select all

function love.load()
	HC = require 'hardoncollider'
	g  = love.graphics
	g.setBackgroundColor (0, 0, 0)
	
	function onCollide(dt, shapeA, shapeB)
		if shapeA == p then
			shapeA:move(x, y)
		else
			shapeB:move(x, y)
		end
		msg = "Colliding!"
	end

	Collider = HC(100, onCollide)

	px = 100
	py = 100
	
	p   = Collider:addRectangle(px, py, 50, 50)
	box = Collider:addRectangle(400, 200, 20, 200)
	g.setBackgroundColor(200, 200, 200)
end

function love.update(dt)
	if love.keyboard.isDown("w") 	 then
	   p:move(0,-200 * dt)
	elseif love.keyboard.isDown("s") then
       p:move(0,200 * dt)
    end
    if love.keyboard.isDown("a") 	 then
       p:move(-200 * dt,0)
    elseif love.keyboard.isDown("d") then
       p:move(200 * dt,0)
    end
    Collider:update(dt)
end

function love.draw()
	local x,y = p:center()
	g.setColor(51, 51, 51)
	p:draw("fill")
	box:draw("fill")
	g.setColor(0, 0, 0)	
end
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: HardonCollider Collision Error

Post by Azhukar »

On line 8: shapeA:move(x, y), the x,y are not defined in scope of calling function.

In other words, you're calling shapeA:move(nil,nil).
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest