Jump to content

xmlLoadFile Bug


Capsinurass

Recommended Posts

OK so what happens is when i try to save a sizable chunk of info to an .xml file, it saves.. but when i try to load the file that i just saved, it will not load it again.... even though the file is there it wont load. You can see this with the following code... use the command "savecar" twice, you will see that when you first use the command it will create the file "Car.xml" and save some info into it. When you use the command a second time it will not load the file but create it again.

Does anyone know how to get this to load the file again?

(There are chat outputs to show this.)

  
local saveTheCar = function ( player ) 
  
    local vehicle = getPlayerOccupiedVehicle ( player ) 
     
    if ( not vehicle ) then 
        outputChatBox ( "You Are Not In A Car!" ) 
        return 
    end 
    local XML = xmlLoadFile ( "Car.xml" ) 
     
    if ( not XML ) then 
        outputChatBox ( "Car.xml Not Found!" ) 
        XML = xmlCreateFile ( "Car.xml", "cars" ) 
        if ( XML ) then 
            outputChatBox ( "Car.xml Created!" ) 
        end 
    end 
     
    local vehicleName = getVehicleName ( vehicle ) 
  
    carNode = xmlCreateSubNode ( XML , "car" ) 
  
    xmlNodeSetAttribute ( carNode, "name", vehicleName ) 
     
    local vehicleID = getVehicleID ( vehicle ) 
    xmlNodeSetAttribute ( carNode, "id", vehicleID ) 
  
    local vehicleHealth = getElementHealth ( vehicle ) 
    xmlNodeSetAttribute ( carNode, "health", vehicleHealth ) 
     
    local paintNode = xmlCreateSubNode ( carNode , "paint" ) 
     
    local color1, color2, color3, color4 = getVehicleColor ( vehicle ) 
    xmlNodeSetAttribute ( paintNode, "color1", color1 ) 
    xmlNodeSetAttribute ( paintNode, "color2", color2 ) 
    xmlNodeSetAttribute ( paintNode, "color3", color3 ) 
    xmlNodeSetAttribute ( paintNode, "color4", color4 ) 
     
    local vehiclePaintjob = getVehiclePaintjob ( vehicle ) 
    xmlNodeSetAttribute ( paintNode, "paintjob", vehiclePaintjob ) 
     
    local upgradeNode = xmlCreateSubNode ( carNode , "upgrade" ) 
     
    for i = 0, 16 do 
        local vehicleUpgrade = getVehicleUpgradeOnSlot ( vehicle, i ) 
        if ( vehicleUpgrade ) then 
            xmlNodeSetAttribute ( upgradeNode, getVehicleUpgradeSlotName ( i ), vehicleUpgrade ) 
        end 
    end 
  
    local stateNode = xmlCreateSubNode ( carNode , "state" ) 
  
    local vehicleDoorState = getVehicleDoorState ( vehicle, 0 ) 
    xmlNodeSetAttribute ( stateNode, "hood", vehicleDoorState ) 
     
    vehicleDoorState = getVehicleDoorState ( vehicle, 1 ) 
    xmlNodeSetAttribute ( stateNode, "trunk", vehicleDoorState ) 
     
    vehicleDoorState = getVehicleDoorState ( vehicle, 2 ) 
    xmlNodeSetAttribute ( stateNode, "front left", vehicleDoorState ) 
     
    vehicleDoorState = getVehicleDoorState ( vehicle, 3 ) 
    xmlNodeSetAttribute ( stateNode, "front right", vehicleDoorState ) 
     
    vehicleDoorState = getVehicleDoorState ( vehicle, 4 ) 
    xmlNodeSetAttribute ( stateNode, "rear left", vehicleDoorState ) 
     
    vehicleDoorState = getVehicleDoorState ( vehicle, 5 ) 
    xmlNodeSetAttribute ( stateNode, "rear right", vehicleDoorState ) 
     
    local wheel1, wheel2, wheel3, wheel4 = getVehicleWheelStates ( vehicle ) 
    xmlNodeSetAttribute ( stateNode, "wheel1", wheel1 ) 
    xmlNodeSetAttribute ( stateNode, "wheel2", wheel2 ) 
    xmlNodeSetAttribute ( stateNode, "wheel3", wheel3 ) 
    xmlNodeSetAttribute ( stateNode, "wheel4", wheel4 ) 
     
    for i = 0, 3 do 
        local vehicleLightState = getVehicleLightState ( vehicle, i ) 
        if ( vehicleLightState ) then 
            xmlNodeSetAttribute ( stateNode, "light" .. i, vehicleLightState ) 
        end 
    end 
     
    for i = 0, 6 do 
        local vehiclePanelState = getVehiclePanelState ( vehicle, i ) 
        if ( vehiclePanelState ) then 
            xmlNodeSetAttribute ( stateNode, "panel" .. i, vehiclePanelState ) 
        end 
    end 
    xmlSaveFile ( XML ) 
    outputChatBox ( "Car.xml Saved!" ) 
    xmlUnloadFile ( XML ) 
end 
  
addCommandHandler ( "savecar", saveTheCar ) 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...