Forum

> > CS2D > Scripts > Save system error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save system error

11 replies
To the start Previous 1 Next To the start

old Save system error

Xirot
User Off Offline

Quote
Hello, since DC added LuaJIT I find this error :

1
LUA ERROR: sys/lua/functions.lua:7: attempt to index local 'file' (a nil value)

1
2
3
4
5
6
7
8
9
10
11
function _save(id)
     local usgn = player(id,"usgn")
     local ip = player(id,"ip")
     if usgn > 0 then
          local file = io.open(dir.."saves/"..usgn..".txt","w+")
          local cell, prison_time, mute_time, red, green, blue, vlu = cell_number[id], prison_seconds[id], mute_seconds[id], Player[id].r, Player[id].g, Player[id].b, Player[id].v
          file:write(cell.."\n"..prison_time.."\n"..mute_time.."\n"..red.."\n"..green.."\n"..blue.."\n"..vlu)
          print("\169000255000Saved "..usgn)
          file:close()
     end
end


So does anyone knows how to fix this?

Thanks.

old Re: Save system error

Talented Doge
User Off Offline

Quote
Either it's the problem of directory or it's the problem of the io.open mode.

I uses w instead of w+. Try w instead.

old Re: Save system error

gamus
User Off Offline

Quote
I had a problem like that. File writing worked just as fine, but the reading was a pain in the cake.

old Re: Save system error

Dousea
User Off Offline

Quote
lua-users wiki: Io Library Tutorial has written
It returns a new file descriptor, or, in case of errors, nil plus an error message.

Probably there's an error when opening the file. So what you need to do is to check if there's any error by using
1
2
3
4
5
6
7
8
9
10
11
12
function _save(id)
	local usgn = player(id,"usgn")
	local ip = player(id,"ip")
	if usgn > 0 then
		local file = assert(io.open(dir.."saves/"..usgn..".txt","w+"))
		local cell, prison_time, mute_time, red, green, blue, vlu = cell_number[id], prison_seconds[id], mute_seconds[id], Player[id].r, Player[id].g, Player[id].b, Player[id].v
		
		file:write(cell.."\n"..prison_time.."\n"..mute_time.."\n"..red.."\n"..green.."\n"..blue.."\n"..vlu)
		print("\169000255000Saved "..usgn)
		file:close()
	end
end
It will print what caused the error. My first guess is there's no saves folder.

old Re: Save system error

_Yank
User Off Offline

Quote
Ensure that there's a sys/lua/admin/saves directory and if you're in linux, ensure that it has the right permissions and onwer.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview