News for hackers. Stuff that matters.
Re:How to make a game from scratch using Lua and Löve by suby on Sunday February 18, 2018 @12:17AM (#16404585)
I'm not OP, but I couldn't get past the fact that arrays start at 1 rather than 0.
Re:How to make a game from scratch using Lua and Löve by grzm on Sunday February 18, 2018 @12:27AM (#16404608)
While many languages follow a 0-indexed convention, as you see here, not all do. Another couple of cases I run into are Postgres arrays, and switching between “first”, “second”, and “nth” in Clojure.

If it helps, you can think 0-indexed as referring to the offset, and 1-indexed as referring to the position. It’s a shame to dismiss the entire language due to what one might argue is a minor aspect.

Re:How to make a game from scratch using Lua and Löve by synthc on Sunday February 18, 2018 @09:03AM (#16406108)
I would not call Clojure 1-indexed though because of 'first', it uses 0-indexing for list, vectors, and arrays.
Re:How to make a game from scratch using Lua and Löve by grzm on Sunday February 18, 2018 @09:29AM (#16406206)
To be clear, I’m not calling Clojure 1-indexed: I provided “nth” and “first” as examples of contrasting 0- and 1-based conventions; in this case within the same language.
Re:How to make a game from scratch using Lua and Löve by runevault on Sunday February 18, 2018 @01:09AM (#16404727)
Clojure being a lisp also has different enough syntax it is easier to jump back and forth because you're doing way more context switching. Lua looks enough like other c-style languages you can forget it is 1 based and make all sorts of nasty mistakes.

You can certainly argue it is unfair, but it is still something that increases the risk of mistakes.

Re:How to make a game from scratch using Lua and Löve by setzer22 on Sunday February 18, 2018 @04:41AM (#16405224)
Replacing (first coll) by (nth 1 coll) in clojure happens to me more often than I'd like to admit
Re:How to make a game from scratch using Lua and Löve by anta40 on Sunday February 18, 2018 @02:54AM (#16404966)
I mostly write in Java for work. Back to the good old high school days, I spent 2 years learning programming in Pascal (yes, Turbo Pascal for DOS!), so seeing arrays started at 1 is not something strange for me :)

Of course, in Pascal you actually can pick any number where the index starts/end.

Re:How to make a game from scratch using Lua and Löve by seibelj on Sunday February 18, 2018 @12:21AM (#16404596)
Totally agree with you. Zero-indexed arrays are one of those language design dogmas that are simply set in stone, really awkward to switch between languages when Lua has such a fundamental difference of opinion.
Re:How to make a game from scratch using Lua and Löve by snarfy on Sunday February 18, 2018 @06:47AM (#16405603)
They don't have to, since Lua tables are hash sets and you can use anything as a key. You can start them at 0 if you want. table[0] = "foo" is valid and works. The downside is you have to add '-1' in a few places, but it's not as many as you'd think. All of my Lua code uses zero based arrays. I think the only place I had to add -1 was initializing numeric for loops.
Re:How to make a game from scratch using Lua and Löve by accatyyc on Sunday February 18, 2018 @06:40AM (#16405579)
Since Lua “arrays” are just tables with numerical keys, couldn’t you just start at 0 if that’s your preference?
Re:How to make a game from scratch using Lua and Löve by rogual on Sunday February 18, 2018 @04:29AM (#16405186)
For me it was the fact that the array ends at the first 'nil' you store in it. 1-based arrays I could get used to; that was just maddening.