jpfed / Adrift

You are a space pilot lost in an endless maze of extraterrestrial caverns. Can you find your way home?
http://www.ludumdare.com/compo/author/jpfed/
2 stars 3 forks source link

Error at level generation #29

Closed dgfitch closed 14 years ago

dgfitch commented 14 years ago

I wish there was an easier way to pull the error out of LOVE... this happened going to level 2 of a Hard game.

This is probably something I boned when I object-ized Level?

objects/Level.lua:397: attempt to index field '?' (a nil value)

Stack traceback: objects/Level.lua:397: in function 'solidTileAt' objects/enemies/HornetEgg.lua:31: in function 'update' objects/Level.lua:46: in function 'update'

jpfed commented 14 years ago

A HornetEgg checks to see if it's about to instantiate a Hornet in a solid area of the level, and if so, it doesn't instantiate that Hornet. I've encountered this error, and staved it off by making the egg round the hornets' coordinates to integers (rounding up in this case). But if an egg were at the very rightward or bottom edge of the level, and then got blown up, then it might be possible for a rounded-up hornet's coordinates to be outside the array bounds.

Basically, I recommend a few changes:

  1. The function should be called solidAt rather than solidTileAt, because in the future we might not be using tiles anyway (don't forget our sweet polygonized dreams).
  2. solidAt (and not the HornetEgg) should be responsible for rounding the coordinates- rounding the coordinates is only an artifact of encoding the level as integer-indexed arrays, which the HornetEgg should not know about
  3. solidAt should also be responsible for bounds-checking itself; if something is outside the bounds of the level, it can be presumed to be solid.