Jump to content

GetVehicleOccupants doubt


DarkLink

Recommended Posts

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 :S

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 :S

Thanks

Link to comment
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 :S

thats my doubt..

soo? :S

Link to comment
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 :S

I will start using a simple for, instead of ipairs in most of cases that I need index 0 :)

Thanks.

Link to comment

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...