Kazafka Posted January 2, 2020 Share Posted January 2, 2020 I don't rally know, how to use multiple nodes in XML files. I've tried to specify an index, but it always returns userdata. My code: Lua (please don't look at the comment, it's in Polish [means: XML file that specifies, who can be policeman, and, specifies police vehicles]): addEventHandler("onResourceStart", root, function() local xml = xmlLoadFile("stuff.xml") --Plik XML określający, kto może być policjantem, oraz, określający samochody policyjne local polmen = xmlNodeGetChildren(xml, 0) local polvehs = xmlNodeGetChildren(xml, 1) for i, node in ipairs(polmen) do policemen[i] = xmlNodeGetValue(node) end xmlUnloadFile(xml1) for i, node in ipairs(polvehs) do policevehs[i] = xmlNodeGetValue(node) end xmlUnloadFile(xml2) end) XML (polish comments [means: <!--<user>(playerName)</user>--> and <!--<vehicle>(vehicleID)</vehicle>-->]): <policemen> <!--<user>(nazwaGracza)</user>--> <user>VaporZ</user> <user>maxeo11</user> </policemen> <policevehicles> <!--<vehicleicle>(idPojazdu)</vehicleicle>--> <vehicle>596</vehicle> <vehicle>523</vehicle> <vehicle>402</vehicle> </policevehicles> Any advance? Link to comment
Moderators IIYAMA Posted January 2, 2020 Moderators Share Posted January 2, 2020 (edited) Aren't you saving userdata instead? Anyway, there are 2 things that I notice. 1. You are not unloading your xml file. But unloading 2 non existing files. 2. Your xml file doesn't have 1 root. It has 2 roots infact. @VaporZ Edited January 2, 2020 by IIYAMA Link to comment
Kazafka Posted January 2, 2020 Author Share Posted January 2, 2020 (edited) 8 minutes ago, IIYAMA said: Aren't you saving userdata instead? Anyway, there are 2 things that I notice. 1. You are not unloading your xml file. But unloading 2 non existing files. 2. Your xml file doesn't have 1 root. It has 2 roots infact. By the way, no, I want to use table. 1. YES XD 2. That's worng? @ 2. - On MTA Reference, they told me, that I can choose what root I want to use, for specifict action. Edited January 2, 2020 by VaporZ Link to comment
Moderators IIYAMA Posted January 2, 2020 Moderators Share Posted January 2, 2020 (edited) 7 minutes ago, VaporZ said: @ 2. - On MTA Reference, they told me, that I can choose what root I want to use, for specifict action. Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root. (xml = fileRoot) <fileRoot> <policemen> <!--<user>(nazwaGracza)</user>--> <user>VaporZ</user> <user>maxeo11</user> </policemen> <policevehicles> <!--<vehicleicle>(idPojazdu)</vehicleicle>--> <vehicle>596</vehicle> <vehicle>523</vehicle> <vehicle>402</vehicle> </policevehicles> </fileRoot> Edited January 2, 2020 by IIYAMA Link to comment
Kazafka Posted January 2, 2020 Author Share Posted January 2, 2020 1 minute ago, IIYAMA said: Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root. <fileRoot> <policemen> <!--<user>(nazwaGracza)</user>--> <user>VaporZ</user> <user>maxeo11</user> </policemen> <policevehicles> <!--<vehicleicle>(idPojazdu)</vehicleicle>--> <vehicle>596</vehicle> <vehicle>523</vehicle> <vehicle>402</vehicle> </policevehicles> </fileRoot> I'll test that 12 minutes ago, IIYAMA said: Just try to give it a root, because I am not sure if MTA, can detect multiple items and based on that create a new file root. <fileRoot> <policemen> <!--<user>(nazwaGracza)</user>--> <user>VaporZ</user> <user>maxeo11</user> </policemen> <policevehicles> <!--<vehicleicle>(idPojazdu)</vehicleicle>--> <vehicle>596</vehicle> <vehicle>523</vehicle> <vehicle>402</vehicle> </policevehicles> </fileRoot> Lua: local xml = xmlLoadFile("policja.xml") local polmen = xmlNodeGetChildren(xml, 0) local polvehs = xmlNodeGetChildren(xml, 1) for i, node in ipairs(polmen) do policemen[i] = xmlNodeGetValue(node) end for i, node in ipairs(polvehs) do policevehs[i] = xmlNodeGetValue(node) end xmlUnloadFile(xml) XML: <root> <policemen> <!--<user>(nazwaGracza)</user>--> <user>VaporZ</user> <user>maxeo11</user> </policemen> <policevehicles> <!--<user>(IDPojazdu)</user>--> <vehicle>596</vehicle> <vehicle>523</vehicle> <vehicle>402</vehicle> </policevehicles> </root> Still nothing, error: [...] expected table at argument 1, got userdata (ipairs error). BTW, I've released: 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