matucha123 Posted February 15, 2012 Share Posted February 15, 2012 OK I'm newbie in LUA 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 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
Castillo Posted February 15, 2012 Share Posted February 15, 2012 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
matucha123 Posted February 15, 2012 Author Share Posted February 15, 2012 Thank you This is working. But how put name and price values in table under id? (I don't know if I said whis right ) Let's say Infernus id = 411, how put "name" and "price" under this id in table? Link to comment
Castillo Posted February 15, 2012 Share Posted February 15, 2012 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
matucha123 Posted February 15, 2012 Author Share Posted February 15, 2012 Thank you very much! Link to comment
TwiX! Posted February 15, 2012 Share Posted February 15, 2012 if u will have =~ 350cars, u will have problem with xml, its so slow, your "ram" will be f*ck*d Link to comment
matucha123 Posted February 15, 2012 Author Share Posted February 15, 2012 So that I should use? 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