Tables being dickey again.

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
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Tables being dickey again.

Post by WolfNinja2 »

More for loops telling me they want tables and not userdata.

Error : Line 30 ; Bad Argument to ipairs , expected table, got userdata.

Line 30 is the ipairs uder bulletUpdate()

Code: Select all

bullet = {}
--
function LOAD_BULLET()
	bullet.speed = 600
	bullet.width = 6
	bullet.height = 6
end
--
function bulletSpawn(x, y, dir)
	table.insert(bullet, {x = x, y = y, dir = dir, speed = bullet.speed, width = bullet.width, height = bullet.height})
end
--
function bulletDraw()
	g.setColor(255, 255, 255, 255)
	g.draw(bullet, v.x, v.y)
end
--
function bulletUpdate(dt)
	for k,v in ipairs(bullet) do
		if v.dir == "right" then
			v.x = v.x + v.speed * dt
		end
		if v.dir == "left" then
			v.x = v.x - v.speed * dt
		end
		if v.dir == "down" then
			v.y = v.y + v.speed * dt
		end
		if v.dir == "up" then
			v.y = v.y - v.speed * dt
		end
	end
end
--
function bulletRemove()
	for k,v in ipairs(bullet) do
		if v.x < -100 or v.y < -100 or v.x > ScreenWidth + 100 or v.y > ScreenHeight + 100 then
			table.remove(bullet, k)
		end
	end
end
--
--PARENT FUNCTIONS
function UPDATE_BULLET(dt)
	bulletUpdate(dt)
	bulletRemove()
end

function DRAW_BULLET()
	bulletDraw()
end
please help, this keeps happening to everything as my game gets larger and it is very frustrating!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Tables being dickey again.

Post by Robin »

Code: Select all

g.draw(bullet, v.x, v.y)
You're trying to draw a table. That doesn't work, obviously. It seems like you don't even have a bullet image.

EDIT: oh, you're getting the opposite error. I suspect you have overridden bullet somewhere with the image of a bullet.

(Again, this would be much easier to solve if you would just follow the forum rules and upload a .love.)
Help us help you: attach a .love.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Tables being dickey again.

Post by WolfNinja2 »

Thank you very much this one is fixed, im an idiot haha

just changed the image to img_bullet instead of ressetting bullet.
Post Reply

Who is online

Users browsing this forum: No registered users and 86 guests