Forum

> > CS2D > Scripts > Save Script...
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save Script...

4 replies
To the start Previous 1 Next To the start

old Save Script...

Homam
User Off Offline

Quote
Hey guys again, i was wonderin' why my save script don't work...

So, here it is:

More >


It saves a file, but when i join the game they say "Your Save File Is Not Found!". There's no errors in the console... Help?

old Re: Save Script...

Banaan
User Off Offline

Quote
First of all, some strange stuff in your code:

1
local prs
is unused.

You don't write anything into the file, you should try it with a file which has content:
1
2
3
4
5
6
7
function Save(id)
	if player(id,"exists") and player(id,"usgn")>0 then
		f = assert(io.open("sys/lua/Script/Saves/Saves.sav"..player(id,"usgn")..".txt","w"))
		f:write("Blah blahblah blah blahblahblah")
		f:close()
	end
end

1
if f then
can mean quite a few things, such as
1
if f ~= nil then
which you want to check, but it can also mean
1
2
3
4
5
if f ~= false then
-- or
if f ~= 0 then
-- or possibly even
if #f > 0 then

So you should use a more explicit
1
if f ~= nil then


--

1
break
can only be used within loops, those things starting with
1
2
3
for
repeat
while

You use it in an 'if' statement - not sure what will happen. Probably just an error.

old Re: Save Script...

Banaan
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
addhook("leave","Save")
function Save(id)
	if player(id,"exists") and player(id,"usgn")>0 then
		f = assert(io.open("sys/lua/Script/Saves/Saves.sav"..player(id,"usgn")..".txt","w"))
		f:write("DataToSave")
		f:close()
	end
end

addhook("join","Load")
function Load(id)
	if player(id,"usgn") > 0 then
		f = io.open("sys/lua/Script/Saves/Saves.sav"..player(id,"usgn")..".txt","r")
		if f ~= nil then
			msg2(id,"©000255000Your save file is found!@C")
			LoadedData = f:read("*all")
			f:close()
		else
			msg2(id,"©255000000Your Save File Is Not Found!@C")
		end
	end
end

There are better ways to save the stuff, but I quickly rewrote it.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview