The Killer Posted January 5, 2014 Share Posted January 5, 2014 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
DNL291 Posted January 5, 2014 Share Posted January 5, 2014 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
The Killer Posted January 5, 2014 Author Share Posted January 5, 2014 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
DNL291 Posted January 5, 2014 Share Posted January 5, 2014 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
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