Markeloff Posted August 31, 2014 Posted August 31, 2014 Hello, So, here's my table. For example, I'm in the first row of the table which index is 0, how to get the next row and its data which is indexed at 1. local radios = { {0,"Radio Off",nil}, {1,"Radio 1","link"}, {2,"Radio 2","link"}, {3,"Radio 3","link"}, {4,"Radio 4","link"}, {5,"Radio 5","link"}, } function setCurrentChannel(id) if (id < 0) or (id > #radios) then return false; end; outputChatBox("setting done") channelID = id; for i,v in ipairs (radios) do if v[1] == id then actual = v[2] suivant = -- is the v[2] of next row of the table previous = -- is the v[2] of previous row of the table outputChatBox(v[2]) end return true; end end
bandi94 Posted August 31, 2014 Posted August 31, 2014 function setCurrentChannel(id) if (id < 0) or (id > #radios) then return false; end; outputChatBox("setting done") channelID = id; for i,v in ipairs (radios) do if v[1] == id then actual = v[2] suivant = v[i+1][2] -- next row data 2 previous = v[i-1][2] -- prev row data 2 outputChatBox(v[2]) end return true; end end
Moderators IIYAMA Posted August 31, 2014 Moderators Posted August 31, 2014 @ bandi94 his code + suivant = v[i+1] and v[i+1][2] or v[1] and v[1][2] -- next row data 2 previous = v[i-1] and v[i-1][2] or v[#v] and v[#v][2] -- prev row data 2
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