Forum

> > CS2D > Scripts > Save system error
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Save system error

11 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Save system error

Xirot
User Off Offline

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

alt Re: Save system error

Talented Doge
User Off Offline

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

alt Re: Save system error

gamus
User Off Offline

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

alt Re: Save system error

Dousea
User Off Offline

Zitieren
lua-users wiki: Io Library Tutorial hat geschrieben
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.

alt Re: Save system error

_Yank
User Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht