please help me debug my code

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
jimjamjahaa
Posts: 17
Joined: Mon Oct 03, 2005 5:00 am

please help me debug my code

Post by jimjamjahaa »

i am trying to implement some clipping in to my game

here are the 2 functions used for this

Code: Select all

function compOutCode(x, y)
	local outcode = 0
	if y <0 then
		outcode = bottom
	    end
	if y > 272 then
	    outcode = top
	    end
	if x < 0 then
	    outcode = outcode + left
	    end
	if x > 480 then
	    outcode = outcode + right
	    end
	return outcode
	end

function drawLineClipped&#40;x0,y0,x1,y1,col&#41;
	local accept, done = false
	local out1, out2, outout, _x, _y = 0
	out1 = compOutCode&#40;x0, y0&#41;
	out2 = compOutCode&#40;x1, y1&#41;


	repeat
		if &#40;out1 == inside and out2 == indide&#41; then
     		accept = true
     		done = true
     		break
		elseif not out1 * out2 == inside then -- <<<HERE!
		    done = true
		    break
		    end

		if out1 == inside then
		    outout = out2
	 	else
	 	    outout = out1
	 	    end

		-- if top in outout
		if outout == 2 or outout == 10 or outout == 11 then
		    _x = x0 + &#40;x1 - x0&#41; * &#40;272 - y0&#41; / &#40;y1 - y0&#41;
			_y = ymax
			end
		-- if bottom
		if outout == 4 or outout == 12 or outout == 13 then
		    _x = x0 + &#40;x1 - x0&#41; * &#40;-y0&#41; / &#40;y1 - y0&#41;;
	        _y = 272
		-- else if right
		elseif outout == 9 or outout == 13 or outout == 11 then
		    _y = y0 + &#40;y1 - y0&#41; * &#40;480 - x0&#41; / &#40;x1 - x0&#41;;
	        _x = 480
		-- else if left
		elseif outout == 8 or outout == 12 or outout == 14 then
		    _y = y0 + &#40;y1 - y0&#41; * &#40;-x0&#41; / &#40;x1 - x0&#41;;
	        _x = 0
	        end

		if outout == out1 then
			x0 = _x
			y0 = _y
			out1 = compOutCode&#40;x0,y0&#41;
		else
		    x1 = _x
		    y1 = _y
		    out2 = compOutCode&#40;x1,y1&#41;
		    end
	until done == true
	if accept == true then
	    screen&#58;drawLine&#40;x0,y0,x1,y1,col&#41;
	    end
	end
i get an error at the place marked "-- <<<HERE!" complaining about doing arithmatic on a boolean variable. i mean, sure its declared as 0, but i dont mean for it to be boolean. the function compOutCode(x,y) will be returning 0 too in this scenario i am using it in.

so umm... help? please say if you dont get what im saying here.
arrggg
Posts: 11
Joined: Thu Sep 29, 2005 10:07 am

Post by arrggg »

is "bottom" and "top" defined?
jimjamjahaa
Posts: 17
Joined: Mon Oct 03, 2005 5:00 am

Post by jimjamjahaa »

Code: Select all

-- globals
red = Color.new&#40;255, 0, 0&#41;;
black = Color.new&#40;0, 0, 0&#41;;
white = Color.new&#40;255, 255, 255&#41;;
green = Color.new&#40;0, 255, 0&#41;;
pi = 3.141592653589
rm_menu = 0
rm_game = 1
room = rm_game

inside = 0
top = 2
bottom = 4
left = 8
right = 9
is the first bit of code in the script :)

edit: its odd, when i get rid of the offending code, it complains about something in the function compOutCode(), but to get to where it has the original error, it must already have executed compOutCode twice.... strange.

i get the feeling it might be doing quite a few passes without an error, and then erroring at the end for some unforseen reason. i dont know. i need to know how to debug really, thus my other thread i posted ....
Post Reply