The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Going crazy over the arrays in lua...

This is a discussion on Going crazy over the arrays in lua... within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; example: tmp{22,75,34} x=tmp[0] x should be 22, but insted lua crashes, cuz there is no element 0 (22 is counted ...

 Tweet
1. ## Going crazy over the arrays in lua...

example:

tmp{22,75,34}
x=tmp[0]

x should be 22, but insted lua crashes, cuz there is no element 0 (22 is counted as element 1)
But if you explicit set tmp[0]=22, then it is 22.(!?!?)

How does arrays work in lua?

2. my understanding is that there is no element [0]

I think it starts on [1]

3. bingo

4. Originally Posted by bigmoor
example:

tmp{22,75,34}
x=tmp[0]

x should be 22, but insted lua crashes, cuz there is no element 0 (22 is counted as element 1)
But if you explicit set tmp[0]=22, then it is 22.(!?!?)

How does arrays work in lua?
Lua doesn't work with indexes, only with keys. If you do tmp{22,75,34}, each of the array value is assigned a key automatically (1,2,3). But if you do tmp[0]=22, then you specify your own key (in this case '0') for the value.

Everything in Lua is basically done with keyed collections rather than arrays. Understand?

(I barely programmed in Lua, but I think this is how it works)

5. Originally Posted by gullwings13
my understanding is that there is no element [0]

I think it starts on [1]
Correct. Lua arrays start at index 1 unless each member is set by assigning according to index (ie. temp[0]=0, temp[1]=1, temp[2]=2, etc). Arrays initialized in list fashion (ie. temp={1, 2, 3...}) are indexed starting at 1.

Coming from years of C/C++, this took me a while to get used to as well.

6. Originally Posted by SkyWalk423
Correct. Lua arrays start at index 1 unless each member is set by assigning according to index (ie. temp[0]=0, temp[1]=1, temp[2]=2, etc). Arrays initialized in list fashion (ie. temp={1, 2, 3...}) are indexed starting at 1.

Coming from years of C/C++, this took me a while to get used to as well.

...:eh:

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 02:54 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2013, Caputo Media, LLC. All Rights Reserved. Cluster C3.
Contact Us | Free Flash Games | Ad Blockers Suck! Why?