Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added assertions for error detection

  • Loading branch information...
commit f1f0ce08f9e7478723eb6445e4b9eb5beb2f5ebe 1 parent affd9b8
@Textmode Textmode authored
Showing with 6 additions and 4 deletions.
  1. +1 −1  entity.lua
  2. +2 −2 powerup.lua
  3. +2 −0  ship.lua
  4. +1 −1  weapon.lua
View
2  entity.lua
@@ -140,7 +140,7 @@ function _M:heal(n)
end
function _M:collidewith(e, dt)
- assert(e, "Can't collide with nothing!")
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
e:dohit(self.damage*dt)
end
View
4 powerup.lua
@@ -62,7 +62,7 @@ function _M:testcollision(e)
end
function _M:doeffect(e)
- assert(e, "Can't effect nothing")
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
local impact = self.shield / self.shieldmax
if self.effect == 'heal10' then
e:heal(e.shieldmax*.1*impact)
@@ -81,7 +81,7 @@ function _M:doeffect(e)
end
function _M:collidewith(e, dt)
- assert(e, "Can't collide with nothing")
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
if e.kind == 'ship' then
self:doeffect(e)
self:die()
View
2  ship.lua
@@ -163,6 +163,7 @@ function ship:die()
end
function ship:addentity(e)
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
if e then
self.entities[#self.entities+1] = e
end
@@ -173,6 +174,7 @@ function ship:shoot()
end
function ship:collidewith(e, dt)
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
if e.kind == 'ship' then
self:dohit(e.damage*dt)
end
View
2  weapon.lua
@@ -45,7 +45,7 @@ function _M:update(dt)
end
function _M:collidewith(e, dt)
- assert(e, "Can't collide with nothing!")
+ assert(e and e._TYPE == 'entity', string.format("Expected 'entity', got '%s' instead.", e and e.type or type(e)))
e:dohit(self.damage)
end
Please sign in to comment.
Something went wrong with that request. Please try again.