Jump to content

K, v in pairs?


Lloyd Logan

Recommended Posts

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

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