Jump to content

I have an error while trying to open my file


amine2

Recommended Posts

I have an error while trying to open my file.

I have an script that will save your text and when you type "/write" h the script will type what you save.

This is the script:

function save(command, text)
local myFile = fileCreate(myPath)
fileOpen(myPath)
fileWrite ( myFile, text )
fileClose(myFile)
end
addCommandHandler("save", save)

function writeSaved()
local myFile2 = fileOpen(myPath)
size = fileGetSize(myFile2)
savedText = fileRead ( myFile2, size )
outputChatBox(savedText)
fileClose(myFile2)
end
addCommandHandler("write", writeSaved)

 

I forgot to tell you in the start i put:

myPath = "test.txt"

Link to comment
2 hours ago, amine2 said:

I have an error while trying to open my file.

I have an script that will save your text and when you type "/write" h the script will type what you save.

This is the script:

function save(command, text)
local myFile = fileCreate(myPath)
fileOpen(myPath)
fileWrite ( myFile, text )
fileClose(myFile)
end
addCommandHandler("save", save)

function writeSaved()
local myFile2 = fileOpen(myPath)
size = fileGetSize(myFile2)
savedText = fileRead ( myFile2, size )
outputChatBox(savedText)
fileClose(myFile2)
end
addCommandHandler("write", writeSaved)

 

I forgot to tell you in the start i put:

myPath = "test.txt"

function save(command, text)
	local myFile = fileExists(myPath) and fileOpen(myPath) or fileCreate(myPath)
	fileOpen(myPath)
	fileWrite ( myFile, text )
	fileClose(myFile)
end
addCommandHandler("save", save)

function writeSaved()
	local myFile2 = fileExists(myPath) and fileOpen(myPath) or fileCreate(myPath)
	size = fileGetSize(myFile2)
	savedText = fileRead ( myFile2, size )
	outputChatBox(savedText)
	fileClose(myFile2)
end
addCommandHandler("write", writeSaved)

 

Link to comment
  • 2 weeks later...

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