Jump to content

get the next row of a table


Emile

Recommended Posts

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

Link to comment

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.

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