Forum

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

Englisch Load/Save system bug

13 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Load/Save system bug

StirlizZ-Fapicon
Super User Off Offline

Zitieren
Hi US, We find strange problem in our Zombies Incoming! script. When it got launch at Linux server, it create strange error:

[16:22:26] LUA ERROR: sys/lua/zombiesincoming/saveload.lua:24: attempt to concatenate a boolean value

Please help us to solve this probles, it`s cause why we can`t release it. (It must been released in March!)


P.S. I hope I don`t brake any rules, when crate this thread.

alt Re: Load/Save system bug

DC
Admin Off Offline

Zitieren
player 1 didn't exist in the moment when this line was executed.
because this is the only possible scenario in which the player Lua command returns a boolean (false) for "usgn".

wrap a
1
if (player(1,"exists")) then
around the whole save code block

alt Re: Load/Save system bug

Lee
Moderator Off Offline

Zitieren
replace with

1
file = io.open("zi_saves/" .. (player(1, "usgn") or "nil") .. ".txt", "r")

if you never create zi_saves/nil.txt, then file will return nil and life goes on.

Problems:
1. You're hard coding the player ID into the system, this is bad.
2. Since you're using USGN as the save file, you will undoubtedly encounter the same exact problem in the save code.

alt Re: Load/Save system bug

Apache uwu
User Off Offline

Zitieren
Are you looping all 32 players to save? Not a good idea, you could instead do this.


1
2
3
4
for key,value in pairs(player(0,"table")) do
	file = io.open("zi_saves/" .. player(value, "usgn") ..".txt", "r")
	file:close()
end

Personally I don't use the io.read very often, if you want to read some data you could easily read them like this.

Suppose you wanted to load your level, the amount of money you have and your experience level.

The format looks like this.

1
23 5000 100

23 is your level, 5000 is the amount of money, and 100 is your experience level.

Now to quickly find these values you could easily do this.

1
2
3
4
5
6
7
8
9
10
11
12
13
function read_line(filelocation, linenum)
	saveline=1
	savestr={}
		for line in io.lines(filelocation) do
			savestr[saveline]=line
			saveline=saveline+1
		end
	return savestr[linenum] 
end
for key,value in pairs(player(0,"table")) do
	v_level,v_money,v_experience=read_line("zi_saves/" ..(player(1, "usgn")..".txt",1):match("(.*) (.*) (.*)")
	--Save v_level,v_money,v_experience to some where else
end

If your data is multilevel/more than one line, you could easily just change read_line(file,line)--line to 2, 3, etc.

alt Re: Load/Save system bug

StirlizZ-Fapicon
Super User Off Offline

Zitieren
Thx your all, guys, there is full code, I`m hope that with your help we released it before I`m leave my home (to voyaje).

There is full script code under spoiler:
Spoiler >
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht