Monument Posted June 25, 2021 Share Posted June 25, 2021 hello i have script but i want save variables in it for example i have x,y,z i want when script stop save x,y,z in file as xml and when script start if found x,y,z in file xml then use it in function Link to comment
Skully Posted June 27, 2021 Share Posted June 27, 2021 (edited) You can use the event onResourceStop to capture the moment a resource script is stopped, and onResourceStart for when it is started. As for saving your variable data into an XML file, there are a variety of XML functions you can use to create a XML file structure with nodes and save your data there, see the following example taken from the xmlSaveFile page: -- Creates a file named "new.xml" with root node "newroot" and childnode "newchild". function createFileHandler() local RootNode = xmlCreateFile("new.xml"," newroot") local NewNode = xmlCreateChild(RootNode, "newchild") xmlSaveFile(RootNode) xmlUnloadFile(RootNode) end addCommandHandler("createfile", createFileHandler) Edited June 27, 2021 by Skully Link to comment
Monument Posted June 27, 2021 Author Share Posted June 27, 2021 20 hours ago, Skully said: You can use the event onResourceStop to capture the moment a resource script is stopped, and onResourceStart for when it is started. As for saving your variable data into an XML file, there are a variety of XML functions you can use to create a XML file structure with nodes and save your data there, see the following example taken from the xmlSaveFile page: -- Creates a file named "new.xml" with root node "newroot" and childnode "newchild". function createFileHandler() local RootNode = xmlCreateFile("new.xml"," newroot") local NewNode = xmlCreateChild(RootNode, "newchild") xmlSaveFile(RootNode) xmlUnloadFile(RootNode) end addCommandHandler("createfile", createFileHandler) i know i have read all xml functions but how to take a value of variable ? as x = x or getElementData(localPlayer) --( x = 1 ) when i start script i want x = 1 Link to comment
βurak Posted June 27, 2021 Share Posted June 27, 2021 (edited) You are using getElementData incorrectly, you should write the key you will receive. getElementData(localPlayer, "Key") Edited June 27, 2021 by Burak5312 Link to comment
Monument Posted June 27, 2021 Author Share Posted June 27, 2021 2 minutes ago, Burak5312 said: You are using getElementData incorrectly, you should write the key you will receive. getElementData(localPlayer, "Key") already i use it as temporary solution but i want when server restart the variable saved 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