Hi,
I am saving some data to a file in data/ore_system, naming the file after the players uniqueid.
for some reason when I read the file it returns nil, if i check if the file exists it returns false. The file definitely exists I can overwrite it fine. It just wont read.
[LUA]print("i was used by "..c:Nick().." "..c:UniqueID())
print(file.Exists(c:UniqueID()..".txt", "DATA/ore_system"))[/LUA]
when writing the data to the file:
[LUA]if file.Exists(c:UniqueID()..".txt", "DATA/ore_system") then
local temp = file.Read(c:UniqueID()..".txt", "DATA/ore_system")
file.Write("ore_system/"..c:UniqueID()..".txt", temp + self.MinedOre)
else
file.Write("ore_system/"..c:UniqueID()..".txt", self.MinedOre)
end[/LUA]
For some reason it just returns false when checking if the file exists then goes to the else statement overwriting the file.
So basically it thinks the file doesnt exist so it overwrites the data (never adding the old with the new, 5 + 5 = 10, just sets it as 5). In another script (npc shop) it has the same problem with not being able to read the file just returning nil or false.
I have tried to restart the server, my gmod, deleting the file and folder.
You'll need to remove your ore_system from the second function argument, and append it to the filename.
local temp = file.Read("ore_system/"..c:UniqueID()..".txt", "DATA")
I don't know if this is right but maybe instead of this:
if file.Exists(c:UniqueID()..".txt", "DATA/ore_system") then
It should be this:
if file.Exists("ore_system/" .. c:UniqueID()..".txt", "DATA") then
Thank you both, that has fixed it
Sorry, you need to Log In to post a reply to this thread.