Page 1 of 1

Cannot execute testSegment - it is nil ?!

Posted: Mon Apr 30, 2012 9:51 pm
by LilaQ
Hello guys,

I just started coding with LUA / LÖVE today. However, I am running in to a problem which I just cannot solve.

I am trying to use the Shape:testSegment(x1, y1, x2, y2) function, but it just won't execute. It always triggers an error: "attempt to call method 'testSegment' (a nil value)"

Here is an example of my code where this error gets triggered. Although I am pretty certain that my code is correct:

Code: Select all

function GetIntersection(cur_shape, y)
	if(cur_shape ~= nil) then
		local left 		= cur_shape:testSegment(wall_left, y)
		local right		= cur_shape:testSegment(wall_right, y)
		if(left == nil or right == nil) then
			return 0
		else
			return (right - left)
		end
	end
	return 0
end

Re: Cannot execute testSegment - it is nil ?!

Posted: Mon Apr 30, 2012 11:21 pm
by felix24
hey man,

testSegment requires 4 arguments. the x and y of the start of the line and the x and y of the end of the line. in your code you are only supplying 2 arguments to each call of testSegment. so that's probably why you are getting that error. it also returns three values, but i'm not sure if you have to assign a variable for all of them. here's how i use it anyway:

Code: Select all

local t, xn, yn = myShape:testSegment(x1, y1, x2, y2)
good luck ^^

Re: Cannot execute testSegment - it is nil ?!

Posted: Tue May 01, 2012 12:24 am
by Boolsheet
Shape:testSegment was probably removed in 0.8.0. The wiki is not fully up to date yet.

Re: Cannot execute testSegment - it is nil ?!

Posted: Tue May 01, 2012 6:28 am
by bartbes
All the testSegments are now superseded by the rayCasts.

Re: Cannot execute testSegment - it is nil ?!

Posted: Tue May 01, 2012 12:58 pm
by LilaQ
Alright, thanks! Will try to build with the RayCasts.

Cheers,