VorenKurn
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 48 |
|
|
| 29 Apr 2012 05:59 AM |
| It feels really odd, because most tables/vectors are supposed to start on 0. Is this because Lua is made this way, or did Roblox change it to this form when they implemented Lua into the game? |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 06:09 AM |
The ROBLOX developers haven't changing anything in the Lua language at all.
They've implemented it as-is and haven't changed a single thing since then.
They've changed lots of libraries and have attached their API to it, but they haven't ever edited anything at all in the language. |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 06:21 AM |
Because it's much easier for newer people to start off with, and Lua was made to be fairly simple.
At least that's my understanding. Prehaps 0-based are easier if you learn them first? |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 06:26 AM |
It makes a little more sense to be able to do:
tab[#tab]
insead of:
tab[#tab-1]
0 is better for computers, 1 is better for people. |
|
|
| Report Abuse |
|
|
oysi92
|
  |
| Joined: 20 Nov 2008 |
| Total Posts: 361 |
|
|
| 29 Apr 2012 06:37 AM |
^ I need to watch the whole SG1 series again. Because I can't remember the exact quote. |
|
|
| Report Abuse |
|
|
NXTBoy
|
  |
| Joined: 25 Aug 2008 |
| Total Posts: 4533 |
|
|
| 29 Apr 2012 09:04 AM |
I like the python way, where you get the last item in the table with `tab[-1]`.
There are lots of times when it makes more sense to start a table at 0. To quote an answer on programmers.stackexchange:
> Half-open intervals compose well. If you're dealing in 0 <= i < lim and you want to extend by n elements, the new elements have indices in the range lim <= i < lim + n. Working with zero-based arrays makes arithmetic easier when splitting or concatenating arrays or when counting elements. One hopes the simpler arithmetic leads to fewer fencepost errors.
This basically means you can do stuff like this with 0-base arrays:
local my2d0BasedArray = {} local width = 10 local height = 8
--0-based 2D getter function getFromMyArray(x, y) return my2d0BasedArray [x + y*width] end
Whereas with 1-based:
local my2d1BasedArray = {} local width = 10 local height = 8
--1-based 2D getter function getFromMyArray(x, y) return my2d1BasedArray[x + (y - 1)*width] end It's a small change, but you end can end up with -1s everywhere |
|
|
| Report Abuse |
|
|
|
| 29 Apr 2012 09:09 AM |
I love the way Python's arrays work.
You can use negative numbers to have fun going backwards with the array, you can also use colons and lots of other things.
They're so easy to manipulate.. |
|
|
| Report Abuse |
|
|