[NOT SOLVED] HardonCollider - polygon:unpack() not working

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
Ovidios
Prole
Posts: 29
Joined: Thu Dec 04, 2014 12:00 pm
Location: Berlin, Germay

[NOT SOLVED] HardonCollider - polygon:unpack() not working

Post by Ovidios »

Whenever i try to call the :unpack() function of the polygon I created using the Collider:addPolygon function I get an error saying the field unpack() is a nil value.
This is how the polygon-table is created:

Code: Select all

function addEnemy(x, y, damage, speed, color, enemytype, health)
	local points = ranPoly(damage, 20)
	enemy.list[#enemy.list] = col:addPolygon(unpack(points))
	enemy.list[#enemy.list].damage = damage
	enemy.list[#enemy.list].color = color
	enemy.list[#enemy.list].speed = speed
	enemy.list[#enemy.list].health = health
	enemy.list[#enemy.list].maxHealth = health
	enemy.list[#enemy.list].enemyType =  enemytype
	print(inspect(enemy.list[#enemy.list]))
end
Thanks in advance,
- Ovidios
Last edited by Ovidios on Thu Jul 09, 2015 6:24 pm, edited 1 time in total.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: HardonCollider - polygon:unpack() not working

Post by ivan »

Depends on what the rest of the code does.
Usually:

Code: Select all

enemy.list[#enemy.list] = 
Overwrites the last numeric element.
Did you mean:

Code: Select all

enemy.list[#enemy.list + 1] = 
I suggest rewriting it as:

Code: Select all

   local points = ranPoly(damage, 20)
   local e = col:addPolygon(unpack(points))
   e.damage = damage
   e.color = color
   e.speed = speed
   e.health = health
   e.maxHealth = health
   e.enemyType =  enemytype
   return e
end

enemy.list[#enemy.list + 1] = newEnemy(x, y, damage, speed, color, enemytype, health)
User avatar
Ovidios
Prole
Posts: 29
Joined: Thu Dec 04, 2014 12:00 pm
Location: Berlin, Germay

Re: HardonCollider - polygon:unpack() not working

Post by Ovidios »

I suggest rewriting it as:

Code: Select all

   local points = ranPoly(damage, 20)
   local e = col:addPolygon(unpack(points))
   e.damage = damage
   e.color = color
   e.speed = speed
   e.health = health
   e.maxHealth = health
   e.enemyType =  enemytype
   return e
end

enemy.list[#enemy.list + 1] = newEnemy(x, y, damage, speed, color, enemytype, health)
Yeah, I wrote it that way before but I read somewhere that the shape tables cannot be copied that easy (for some reason I didn't understand ^^). I thus changed it.
Returning it to the way you suggested it didn't help. I still can't call :unpack()... :(
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 84 guests