Forum

> > CS2D > Scripts > Error in save/load value script.
Forums overviewCS2D overview Scripts overviewLog in to reply

English Error in save/load value script.

8 replies
To the start Previous 1 Next To the start

old Error in save/load value script.

muxarus
User Off Offline

Quote
Hi us nrealSoftWare!
Today i got idea to make jobs in my server so then i maked one script for save and load values. but my script doesn't loading variables
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
job = {2}

addhook("join","load_job")
addhook("leave","save_job")
function load_job(id)
if (player(id,"usgn")>0) then
local filename = "sys/lua/rp/money/account/%s.txt"
local file = io.open(filename:format(player(id,"usgn"), "r"))
local line
if not file then
line = {2}
else
line = file:read("*a"):split()
end
job[id] = tonumber(line[2])
msg2(id,"©255000000Your job is" ..job[id])
job=0
end
end

function save_job(id)
if (player(id,"usgn")>0) then
io.output(io.open("sys/lua/rp/money/account/"..player(id,"usgn").."Job.txt","w+"))
io.write(n/ job[id])
io.close()
end
end
EDIT:
i have new errors:
"server.lua:16: attempt to concatenate field '?' (a nil value)"
and 
"server.lua:24: attempt to perform arithmetic on global 'n' (a nil value)
edited 6×, last 04.02.15 04:34:41 pm

old Re: Error in save/load value script.

Joni And Friends
User Off Offline

Quote
Try this
Click me >

old Re: Error in save/load value script.

THEMUD
User Off Offline

Quote
Do you mean this error?
1
2
3
"server.lua:16: attempt to concatenate field '?' (a nil value)"
and 
"server.lua:24: attempt to perform arithmetic on global 'n' (a nil value)

Change the variable "job" like this:
From:
1
job=0
To:
1
job = {0}

At the line 17. The way you declared the variable causes all these problems.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview