Jump to content

get the next row of a table


Emile

Recommended Posts

Posted

Hello,

I'm scripting a bus driver job and I have a location table.

local stops = { 
{1825.586, -1827.725, 12.414}, 
{1976.795, -1756.753, 12.383}, 
... 
} 

and I want to make it so when the player hits the marker, it gets the next location/row. I tried with

for i,v in ipairs(stops) do 
local x,y,z = v[i+1] 

but it doesnt work.

Thanks

fulltheftauto.net

Posted

Use a variable with the value of the first table index and increase it (+ 1) when the player hits the marker.

And use that variable to get the next location, like:

local x, y, z = unpack(stops[currentIndex]) 

'currentIndex' must have the index which is the value of the next location.

Please do not PM me with scripting related question nor support, use the forums instead.

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...