Jump to content

save variable


Monument

Recommended Posts

Posted

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

 

Posted (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 by Skully
Posted
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

Posted (edited)

 

You are using getElementData incorrectly, you should write the key you will receive.

getElementData(localPlayer, "Key")

 

Edited by Burak5312
Posted
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

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