Cannot execute testSegment - it is nil ?!

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
LilaQ
Prole
Posts: 7
Joined: Mon Apr 30, 2012 9:45 pm

Cannot execute testSegment - it is nil ?!

Post 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
User avatar
felix24
Party member
Posts: 163
Joined: Tue Jul 26, 2011 4:51 pm
Contact:

Re: Cannot execute testSegment - it is nil ?!

Post 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 ^^
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Cannot execute testSegment - it is nil ?!

Post by Boolsheet »

Shape:testSegment was probably removed in 0.8.0. The wiki is not fully up to date yet.
Shallow indentations.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Cannot execute testSegment - it is nil ?!

Post by bartbes »

All the testSegments are now superseded by the rayCasts.
LilaQ
Prole
Posts: 7
Joined: Mon Apr 30, 2012 9:45 pm

Re: Cannot execute testSegment - it is nil ?!

Post by LilaQ »

Alright, thanks! Will try to build with the RayCasts.

Cheers,
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 1 guest