Jump to content

XML


StefanAlmighty

Recommended Posts

Hi, so I've created a very basic script which loads text into a GUI Memo from XML. I'm working on making it so in-game admins are able to edit the text in-game and make it save back to the XML.

However my issue is the following: Everything works, except when the resource is restarted, the XML loads the old text and not what has been edited before the restart. I'm assuming it's not saving properly to the XML file.

Here is my code which saves it:

local function updateContent(theTab) 
    xmlFile, theText = nil, nil 
    if theTab == tabRules then 
        xmlFile = xmlLoadFile( "rules.xml" ) 
        theText = guiGetText(memoRules) 
    elseif theTab == tabAdmins then 
        xmlFile = xmlLoadFile("admins.xml") 
        theText = guiGetText(memoAdmins) 
    elseif theTab == tabScripts then 
        xmlFile = xmlLoadFile("scripts.xml") 
        theText = guiGetText(memoScripts) 
    else 
        outputChatBox("Error 02") 
        return false 
    end 
    xmlNodeSetValue(xmlFile, theText) 
    xmlSaveFile(xmlFile) --Save the xml from memory for use next time 
    xmlUnloadFile(xmlFile) --Unload the xml from memory 
    outputChatBox("Saved.") 
end 
  
addEventHandler ("onClientGUIClick", root, 
function () 
    if source == buttonRules then 
        updateContent(tabRules) 
    elseif source == buttonAdmins then 
        updateContent(tabAdmins) 
    elseif source == buttonScripts then 
        updateContent(tabScripts) 
    end 
end) 
  
function ClientResourceStop () 
    xmlSaveFile(xmlFile) --Save the xml from memory for use next time 
    xmlUnloadFile(xmlFile) --Unload the xml from memory 
end 
addEventHandler ("onClientResourceStop", resourceRoot, ClientResourceStop ) 

Link to comment

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