Jump to content

save variable


Monument

Recommended Posts

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 by Skully
Link to comment
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
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

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