Lloyd Logan Posted January 15, 2013 Share Posted January 15, 2013 Hey, In alot of the community scripts and WIKI examples, There's a line "for k, v in ipairs" what does this mean? and string.byte, what does this mean? full : function startup() local file = xmlLoadFile("pns.xml") for k, v in ipairs(xmlNodeGetChildren(file)) do local pos = split(xmlNodeGetAttribute(v,"pos"),string.byte(",")) local marker = createMarker(pos[1],pos[2],pos[3],"cylinder") createBlipAttachedTo(marker,63,2,255,0,0,255,0,250) setElementData(marker,"pnsMarker",true) setGarageOpen(tonumber(xmlNodeGetAttribute(v,"garage")),true) end xmlUnloadFile(file) end addEventHandler("onResourceStart",getResourceRootElement(),startup) Thanks Lloyd Link to comment
psydomin Posted January 15, 2013 Share Posted January 15, 2013 It is a loop through a table "for" every "k" (key/index) and ", v" (value) "in ipairs(tableName)" (valid k and v on the same row of the table tableName) "do" something Link to comment
Lloyd Logan Posted January 15, 2013 Author Share Posted January 15, 2013 It is a loop through a table"for" every "k" (key/index) and ", v" (value) "in ipairs(tableName)" (valid k and v on the same row of the table tableName) "do" something Ahh, may be a bit much but could you give me an example Link to comment
psydomin Posted January 15, 2013 Share Posted January 15, 2013 table1 = { [1] = {"This is the first row"}, [2] = {"This is the second row"} } for k, v in ipairs(table1) do outputChatBox("This is the row's index: "..k..", and this is the value of that row: "..v ) end it should output on the chat box:" This is the row's index: 1, and this is the value of that row: This is the first row This is the row's index: 2, and this is the value of that row: This is the second row " Link to comment
Lloyd Logan Posted January 15, 2013 Author Share Posted January 15, 2013 table1 = { [1] = {"This is the first row"}, [2] = {"This is the second row"} } for k, v in ipairs(table1) do outputChatBox("This is the row's index: "..k..", and this is the value of that row: "..v ) end it should output on the chat box:" This is the row's index: 1, and this is the value of that row: This is the first row This is the row's index: 2, and this is the value of that row: This is the second row " Thank you very much! I understand this quite a bit more! Link to comment
Castillo Posted January 15, 2013 Share Posted January 15, 2013 Maybe you already know this, but "k" and "v" can be anything, doesn't has to be these two letters. Link to comment
Lloyd Logan Posted January 15, 2013 Author Share Posted January 15, 2013 Maybe you already know this, but "k" and "v" can be anything, doesn't has to be these two letters. I didn't, Thanks! Link to comment
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