Jump to content

File Loading and Editing


ShayF2

Recommended Posts

I want to use a script to make a custom help.xml file that updates everytime a setting is changed, and settings can only change when the script restarts so it makes it perfect. Settings are within the lua file as variables.
I also have a setting in the lua file which determines whether or not to even have a help.xml file. For some reason I couldn't get this to work. I basically wanted to open and then modify the meta.xml to put the help.xml in it when the setting is set to 'true' and then when it is false I wanted to remove that help.xml from the meta.xml. Unfortunately, files will not create, files will not be read, files will not be written, and no errors or warnings are produced. My friend suggested that I use xml functions to do this, but they are not for what I want to do. They are for saving data, not setting/replacing text in a file. I would like some help on this part of my project, in an attempt to get it functional.
I will post the current code below.
 

function makeHelpFile()
	local meta = 'meta.xml'
	local directory	= 'help.xml'
	if not fileExists(directory) then
		local file = fileCreate(directory)
		fileClose(file)
	end
	local helpFile = fileOpen(directory)
	local helpSize = fileGetSize(helpFile)
	local helpBuffer = fileRead(helpFile,helpSize)
	local metaFile = fileOpen(meta)
	local metaSize = fileGetSize(metaFile)
	local metaBuffer = fileRead(metaFile,metaSize)
	if string.find(metaBuffer,'</meta>',1,true) then
		local text = string.gsub(metaBuffer,'</meta>','<config src="help.xml" type="client"/>\n</meta>')
		fileWrite(metaFile,text)
		fileClose(metaFile)
	end
end

 

Link to comment
  • Administrators

I'm not sure what you mean with regards to XML functions: "They are for saving data, not setting/replacing text"

With XML functions you can open files, search for tags/data, change their attributes, add tags/attributes, save them, and pretty much everything else you're wanting to do.

 

tl;dr - use XML functions

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