HC update error [solved]

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
balloonimal
Prole
Posts: 3
Joined: Sun Apr 10, 2016 3:40 pm

HC update error [solved]

Post by balloonimal »

Hi! I just started checking out Löve, and was following this tutorial for HC, using version eac8874, Löve 0.10.1 and 0.9.2. I noticed a few things were deprecated (addCircle -> circle) and switched them out, and everything looks fine except that Collider:update(dt) keeps throwing the error.

Code: Select all

main.lua:73: attempt to call method 'update' (a nil value)

Traceback

main.lua:73 in function 'update'
[C]: in function 'xpcall'
I've been combing through Lua, Löve, and HC docs and can't find anything, but I'm new to this so maybe I'm just not interpreting things correctly.

Thanks for any help/explanation.
Attachments
hcpong.love
(36.97 KiB) Downloaded 102 times
Last edited by balloonimal on Tue Apr 12, 2016 6:45 pm, edited 1 time in total.
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: HC update error

Post by Sheepolution »

It's because this is an old tutorial.

Here's the up-to-date documentation: http://hc.readthedocs.org/en/latest/
balloonimal
Prole
Posts: 3
Joined: Sun Apr 10, 2016 3:40 pm

Re: HC update error

Post by balloonimal »

I know, I said all that in the first post.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: HC update error

Post by vrld »

Then why do you expect the old interface to work? HC.update is no more. You have to check for collisions yourself. See also the second paragraph in the documentation that Sheepolution linked to.

Sidenote: How did you find the old documentation? That shouldn't be accessible anymore :huh:
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
balloonimal
Prole
Posts: 3
Joined: Sun Apr 10, 2016 3:40 pm

Re: HC update error

Post by balloonimal »

Strange, I thought I saw it. Thanks for pointing that out! In case anyone else is looking for this:

Code: Select all

collider = require('hc')

hc = collider.new(150)

function love.load()

	ball = hc:circle(400, 300, 10)
	paddleLeft = hc:rectangle(10, 250, 20, 100)
	paddleRight = hc:rectangle(770, 250, 20, 100) 
	
	ball.velocity = {x = -100, y = 0}
	
end


function love.update(dt)

	ball:move(ball.velocity.x*dt, ball.velocity.y*dt)
	
	if love.keyboard.isDown('w') then
		paddleLeft:move(0, -100*dt)
	elseif love.keyboard.isDown('s') then
		paddleLeft:move(0, 100*dt)
	end

	if love.keyboard.isDown('up') then
		paddleRight:move(0, -100*dt)
	elseif love.keyboard.isDown('down') then
		paddleRight:move(0, 100*dt)
	end

	if love.keyboard.isDown('escape') then
		love.event.push('quit')
	end

	
	local collisions = hc:collisions(ball)
	
	for other in pairs(collisions) do
		if other == goalLeft then
			ball.velocity = {x = 100, y = 0}
			ball:moveTo(400,300)
		elseif other == goalRight then
			ball.velocity = {x = -100, y = 0}
			ball:moveTo(400,300)
		elseif other == borderTop or other == borderBottom then
		
			ball.velocity.y = -ball.velocity.y
		else

			local px,py = other:center()
			local bx,by = ball:center()
			local dy = by - py			
			ball.velocity.x = -ball.velocity.x
			ball.velocity.y = dy

			
			local len = math.sqrt(ball.velocity.x^2 + ball.velocity.y^2)
			ball.velocity.x = ball.velocity.x / len * 100
			ball.velocity.y = ball.velocity.y / len * 100
		
		end
	end 

end

function love.draw()

	ball:draw('line', 16)
	paddleLeft:draw('line')
	paddleRight:draw('line')

end

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 6 guests