Jump to content

[Question] xml


The Killer

Recommended Posts

hello

i have a question, how can i make

when someone click on the 'checkbox'

if he clicked then what he wroted on the edit will be save

but how can i make it if he quit and join again

what he wroted before he will find it

i try to do it like that :

addEventHandler("onClientResourceStart",resourceRoot,  
    function ( )  
    local XMLFile = xmlCreateFile ( "Save.xml", "XML" )  
    local CreateChild = xmlCreateChild(XMLFile, "XML")  
    xmlSaveFile ( XMLFile )  
    outputChatBox("File created !", 0, 255, 0) 
 end 
) 
  
addEventHandler("onClientGUIClick",save,  
function  (  ) 
        local XMLFile = xmlLoadFile ( "Save.xml" )  
        if ( XMLFile ) then  
            local Child = xmlFindChild ( XMLFile, "UserName", 0 )  
            local Name = guiGetText ( user )  
            xmlNodeSetAttribute ( Child,"Name",Name )  
            xmlSaveFile ( XMLFile )  
            xmlUnloadFile ( XMLFile )  
            outputChatBox("Saved", 0, 255, 0) 
    end 
end,false 
) 

it save in the xml file

but if i quit and join i can't find it

so, help please !

Link to comment

Try this:

  
addEventHandler("onClientResourceStart",resourceRoot, 
    function ( ) 
    local XMLFile = xmlCreateFile ( "Save.xml", "XML" ) 
    local CreateChild = xmlCreateChild(XMLFile, "UserName") 
    xmlSaveFile ( XMLFile ) 
    outputChatBox("File created !", 0, 255, 0) 
 end 
) 
  
addEventHandler("onClientGUIClick",save, 
function  (  ) 
        local XMLFile = xmlLoadFile ( "Save.xml" ) 
        if ( XMLFile ) then 
            local Child = xmlFindChild ( XMLFile, "UserName", 0 ) 
            local Name = tostring(guiGetText(user)) 
            if guiCheckBoxGetSelected(guiCheckBox) then 
                if (xmlNodeGetValue(Child) ~= Name) then 
                    xmlNodeSetValue(Child, Name) 
                end 
            end 
            xmlSaveFile ( XMLFile ) 
            xmlUnloadFile ( XMLFile ) 
            outputChatBox("Saved", 0, 255, 0) 
    end 
end,false 
) 

P.S.: 'guiCheckBox' must be defined.

Link to comment

it's not save

Hmm.. but i don't want it when the resource start the file will create, no i try to remove it like this:

    addEventHandler("onClientGUIClick",save, 
    function  (  ) 
            local XMLFile = xmlLoadFile ( "Save.xml" ) or xmlCreateFile ( "Save.xml", "XML") 
            if ( XMLFile ) then 
                local Child = xmlFindChild ( XMLFile, "UserName", 0 ) 
                local Name = tostring(guiGetText(user)) 
                if guiCheckBoxGetSelected(guiCheckBox) then 
                    if (xmlNodeGetValue(Child) ~= Name) then 
                        xmlNodeSetValue(Child, Name) 
                    end 
                end 
                xmlSaveFile ( XMLFile ) 
                xmlUnloadFile ( XMLFile ) 
                outputChatBox("Saved", 0, 255, 0) 
        end 
    end,false 
    ) 

but didn't save !

Link to comment

Try this and make sure you defined guiCheckBox/guiEdit:

  
addEventHandler("onClientResourceStart",resourceRoot, 
    function ( ) 
    local username = loadLoginUsernameFromXML() 
    guiSetText(guiEdit, username) 
 end 
) 
  
addEventHandler("onClientGUIClick",save, 
function  (  ) 
local XMLFile = xmlLoadFile ( "Save.xml" ) or xmlCreateFile ( "Save.xml", "XML") 
    if ( XMLFile ) then 
        local Child = xmlFindChild ( XMLFile, "UserName", 0 ) or xmlCreateChild(XMLFile, "UserName") 
        local Name = tostring(guiGetText(user)) 
        if (Name == "") then return end 
        if guiCheckBoxGetSelected(guiCheckBox) then 
            if (xmlNodeGetValue(Child) ~= Name) then 
                xmlNodeSetValue(Child, Name) 
            end 
        end 
        xmlSaveFile ( XMLFile ) 
        xmlUnloadFile ( XMLFile ) 
        outputChatBox("Saved", 0, 255, 0) 
    end 
end,false 
) 
  
function loadLoginUsernameFromXML() 
    local xmlFile = xmlLoadFile ("Save.xml") 
    if not xmlFile then return false end 
  
    local usernameNode = xmlFindChild (xmlFile, "UserName", 0) 
    if usernameNode then 
        return xmlNodeGetValue(usernameNode) 
    else 
        return "" 
    end 
    xmlUnloadFile(xmlFile) 
end 

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