DarkLink Posted June 29, 2011 Share Posted June 29, 2011 Ok guys I readed something about tables at LUA, and its says that a table always start with index 1 not zero. But then I see this example: https://wiki.multitheftauto.com/wiki/GetVehicleOccupants And I cant understand it I mean, getVehicleOccupants, will always get players on seats 1, 2, and 3 right? because there is no index for seat 0 on a table.. And also it says : Returns Returns a table with contents... table[seat] = occupant And if a table cant have a index 0, it will only gives the passengers, right ? seat 1, seat 2, and seat 3 ? Can someone help me , need to understand this Thanks Link to comment
Castillo Posted June 29, 2011 Share Posted June 29, 2011 There's an example, I just tested it and it outputs the correct data: ------------------------------------ Seat 0: [sANL]Castillo Seat 1: <empty> ------------------------------------ Link to comment
DarkLink Posted June 29, 2011 Author Share Posted June 29, 2011 There's an example, I just tested it and it outputs the correct data: ------------------------------------ Seat 0: [sANL]Castillo Seat 1: <empty> ------------------------------------ thanks for ur help castillo but I dont get it how can it be possible.. The first iteration of the for is seat = 0 , then will look for occupant[0].. but I read on lua tutorials that there isnt any 0 index for tables thats my doubt.. soo? Link to comment
BinSlayer1 Posted June 29, 2011 Share Posted June 29, 2011 It's just the ipairs loop that can only start from 1. Looping through a table (traditionally, by only changing the iterator) doesn't count I believe Link to comment
DarkLink Posted June 29, 2011 Author Share Posted June 29, 2011 It's just the ipairs loop that can only start from 1.Looping through a table (traditionally, by only changing the iterator) doesn't count I believe Okay thanks, so there is index 0 , didnt understand that on the lua archives I will start using a simple for, instead of ipairs in most of cases that I need index 0 Thanks. Link to comment
qaisjp Posted June 29, 2011 Share Posted June 29, 2011 Basically, when you loop, it needs to start from a specific number to loop from, since default is 1, it starts from 1. So if i did: random = { [-99] = "hai", [99] = "hello" } for i,v in ipairs(random) outputChatBox(v) end I would only get "hello" since the index value is -99, which is less that 1 Link to comment
SDK Posted June 29, 2011 Share Posted June 29, 2011 That's wrong actually, it wouldn't output anything. ipairs() starts from index [1] and stops when the next value is 'nil'. http://codepad.org/qDdrWXgi Link to comment
DarkLink Posted June 29, 2011 Author Share Posted June 29, 2011 That's wrong actually, it wouldn't output anything. ipairs() starts from index [1] and stops when the next value is 'nil'.http://codepad.org/qDdrWXgi Thanks alot bro, I understand it Cheers Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now