Jump to content

Putting XML result's into table


matucha123

Recommended Posts

OK I'm newbie in LUA :roll:

Now I'm trying to make loading from XMl file.

My script(client side):

local carlist = {} 
  
function updateCarsList () 
    local meta = xmlLoadFile("carshop/settings.xml") 
    local id = xmlNodeGetAttribute(meta, "id") 
    local name = xmlNodeGetAttribute(meta, "name") 
    local price = xmlNodeGetAttribute(meta, "price") 
    carlist[tonumber(id)] = name  
    xmlUnloadFile(meta) 
    outputDebugString(tostring(carlist[411])) 
end 

XML file:

"411" name="Infernus" price="180000" />  

How can I put all 3 values in table?

How read all lines?

Can someone explain for me "for" cycles? I can't get them :? . In C they are more understandable for me 8)

And other question. Lets say I have in meta.xml defined setting (editable in game via admin panel). How can I spot changes in it (Let's say blur level)?

Link to comment
local carlist = {} 
  
function updateCarsList () 
    local meta = xmlLoadFile("carshop/settings.xml") 
    for index, car in ipairs(xmlNodeGetChildren(meta)) do 
        local id = xmlNodeGetAttribute(car, "id") 
        local name = xmlNodeGetAttribute(car, "name") 
        local price = xmlNodeGetAttribute(car, "price") 
        carlist[tonumber(id)] = name 
        outputDebugString(tostring(carlist[411])) 
    end 
    xmlUnloadFile(meta) 
end 

Link to comment
local carlist = {} 
  
function updateCarsList () 
    local meta = xmlLoadFile("carshop/settings.xml") 
    for index, car in ipairs(xmlNodeGetChildren(meta)) do 
        local id = xmlNodeGetAttribute(car, "id") 
        local name = xmlNodeGetAttribute(car, "name") 
        local price = xmlNodeGetAttribute(car, "price") 
        carlist[tonumber(id)] = {name, price} 
        outputDebugString(tostring(carlist[id][1]) ..": ".. tostring(carlist[id][2])) 
    end 
    xmlUnloadFile(meta) 
end 

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