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 Some people want it to happen, some wish it would happen, others make it happen.
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 Ingame Name : |DGT|Puma DGT Clan Server 24/7 Owner/Scripter MultiGameMode in progress :
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 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
Markeloff Posted August 31, 2014 Author Posted August 31, 2014 It's solved, thank you guys. Some people want it to happen, some wish it would happen, others make it happen.
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