Lloyd Logan Posted January 15, 2013 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
psydomin Posted January 15, 2013 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
Lloyd Logan Posted January 15, 2013 Author 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
psydomin Posted January 15, 2013 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 "
Lloyd Logan Posted January 15, 2013 Author 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!
Castillo Posted January 15, 2013 Posted January 15, 2013 Maybe you already know this, but "k" and "v" can be anything, doesn't has to be these two letters.
Lloyd Logan Posted January 15, 2013 Author 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!
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