Jump to content

XML loading


Chronic

Recommended Posts

Posted

Hey guys, I'm having a problem with xmlLoadFile

--top of the script 
xmlClientSettingsFile = xmlLoadFile ( "files/settings.xml" ) 
if xmlClientSettingsFile then 
    outputChatBox ( "File Loaded" ) 
elseif not xmlClientSettingsFile then 
    xmlClientSettingsFile = xmlCreateFile ( "files/settings.xml", "settings" ) 
    if xmlClientSettingsFile then 
        outputChatBox ( "Works dawg" ) 
    else outputChatBox ( "Nope" ) 
    end 
end 

The file exists in my MTA\mods\deathmatch folder, but it doesn't load for some reason. It always creates a new file at line 6, but still outputs "Nope" at line 9

Posted

1. Is your script clientside or serverside (Regarding your script I guess clientside?)

2. Where does it create a file, clientside or serverside?

Posted

I think to actually create an xml file successfully you need to use xmlCreateFile in conjunction with xmlSaveFile, so like this:

  
xmlClientSettingsFile = xmlLoadFile ( "files/settings.xml" ) 
if xmlClientSettingsFile then 
    outputChatBox ( "File Loaded" ) 
elseif not xmlClientSettingsFile then 
    xmlClientSettingsFile = xmlCreateFile ( "files/settings.xml", "settings" ) 
    if xmlClientSettingsFile then 
        outputChatBox ( "Works dawg" ) 
        --Complete your work on the file here. 
        xmlSaveFile(xmlClientSettingsFile) --Save it permanently. 
        xmlUnloadFile(xmlClientSettingsFile) --Unload it from memory when you are done. 
    else outputChatBox ( "Nope" ) 
    end 
end 
  

If you are using xmlCreateFile server-side then the file will be saved in [MTA directory]/server/resources/[your resource/path here].

If you are using it client-side then it will be saved on the client's computer, in [MTA directory]/mods/deathmatch/resources/[your resource/path here]

Posted

Yes it's saved to /mods/deathmatch/resources[my resource/path here] (client-side)

The file is there, but it doesn't load, even if it creates a new one.

Posted
    xmlClientSettingsFile = xmlLoadFile ( "files/settings.xml" ) 
    if xmlClientSettingsFile then 
        outputChatBox ( "File Loaded" ) 
    else 
        xmlClientSettingsFile = xmlCreateFile ( "files/settings.xml", "settings" ) 
    end 
    if xmlClientSettingsFile then 
        outputChatBox ( "Works dawg" ) 
    else  
        outputChatBox ( "Nope" ) 
    end 

You checked the xmlClientSettingsFile inside else only function, that is why it didn't check

Posted
    xmlClientSettingsFile = xmlLoadFile ( "files/settings.xml" ) 
    if xmlClientSettingsFile then 
        outputChatBox ( "File Loaded" ) 
    else 
        xmlClientSettingsFile = xmlCreateFile ( "files/settings.xml", "settings" ) 
    end 
    if xmlClientSettingsFile then 
        outputChatBox ( "Works dawg" ) 
    else  
        outputChatBox ( "Nope" ) 
    end 

You checked the xmlClientSettingsFile inside else only function, that is why it didn't check

Thanks, it works

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