ViRuZGamiing Posted June 5, 2014 Posted June 5, 2014 Hello guys, I'm about to improve my script from Tables to XML but I need to know something about it. Could you guys explain me some XML Functions and which ones I need to use. Probably; xmlCreateFile xmlLoadFile xmlSaveFile "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
ViRuZGamiing Posted June 5, 2014 Author Posted June 5, 2014 Already made this and works: function createFileHandler() if xmlLoadFile(":xmltest/new.xml") then outputChatBox("Succesfully loaded!", thePlayer) else local RootNode = xmlCreateFile("new.xml"," newroot") local NewNode = xmlCreateChild(RootNode, "newchild") xmlSaveFile(RootNode) outputChatBox("File created!", thePlayer) end end addCommandHandler("createfile", createFileHandler) Creates this: < newroot> >> newroot> But idk what Root and Child are. "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
ViRuZGamiing Posted June 5, 2014 Author Posted June 5, 2014 Did some research okay i know what childern and root are. First I've created an XML on command function createFileHandler() if xmlLoadFile(":xmltest/vehicles.xml") then outputChatBox("Succesfully loaded!", thePlayer) else local vehicles = xmlCreateFile("vehicles.xml"," vehicles") local SF = xmlCreateChild(vehicles, "SF") local SFCar1 = xmlCreateChild(SF, "Car 1") local SFCar2 = xmlCreateChild(SF, "Car 2") local SFCar3 = xmlCreateChild(SF, "Car 3") local LS = xmlCreateChild(vehicles, "LS") local LSCar1 = xmlCreateChild(LS, "Car 1") local LSCar2 = xmlCreateChild(LS, "Car 2") local LSCar3 = xmlCreateChild(LS, "Car 3") local LV = xmlCreateChild(vehicles, "LV") local LVCar1 = xmlCreateChild(LV, "Car 1") local LVCar2 = xmlCreateChild(LV, "Car 2") local LVCar3 = xmlCreateChild(LV, "Car 3") xmlSaveFile(vehicles) outputChatBox("File created!", thePlayer) end end addCommandHandler("createfile", createFileHandler) The above part works but now I wanted to try and use it and this didn't work for me. No Errors. addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function() local xml = xmlLoadFile("vehicles.xml") local vehicleNodes = xmlNodeGetChildren(xml) g_Vehicles = {} for i,node in ipairs(vehicleNodes) do g_Vehicles[i] = xmlNodeGetValue(node) end xmlUnloadFile(xml) end ) addCommandHandler("createvehicle", function() local allVehicles = #g_Vehicles local vehicle = g_Vehicles[math.random(allVehicles)] createVehicle(vehicle) end ) When I put some Coordinates in the XML Childern it resets "If debugging is the process of removing software bugs, then programming must be the process of putting them in."
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