Hacker News new | past | comments | ask | show | jobs | submit login

48 hours writing a game in Lua (which indexes from 1) drives this home: in tile-based games, converting screen co-ordinates into tile co-ordinates results in zero-based indices. My graphics routines were full of +1s and -1s as a result.

Generally any time array indexing intersects with mathematics you are going to get the same issue.

That combined with the fact that, in Lua, sometable[0] doesn't produce a not-present exception (it returns 'nil') resulted in a lot of unnecessary cursing.




You can use a metatable to change this behaviour, either by reindexing, or by returning an error on lookups to values not in the range 1 to #table.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: