English Load function is not working.

4 replies
Goto Page
To the start Previous 1 Next To the start
16.11.16 01:33:39 pm
Up
muxarus
User
Offline Off
I have save function and load func. So save func is working good but the load is not loading variables from a .txt file.
There is a code:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
elo = {}
elo_test_try = {}
pl = {}

for id=1,32 do
pl[id]={}
elo_test_try[id]=5
elo[id]=40
end

addhook("join","_join")
function _join(id)
if player(id,"usgn")>0 then
local dir="sys/lua/accounts/%s.txt"
local file = io.open(dir:format(player(id,"usgn"), "r"))
if file then
local string1, string2, string3, string4, string5 = file:read("*n","*n","*n","*n","*n")
elo[id] = string2
elo_test_try[id] = string3
pl[id].tag = string4
file:close()
end
end


problems:
1) this code is NOT loading string1. so any variable that =string1 will be nil or *n (only elo[id] will be *n but other vars will be nil).
2) this code is loading only 1 variable that first than others.
IMG:http://steamsignature.com/status/german/76561198081961553.png
IMG:http://steamsignature.com/AddFriend.png
16.11.16 02:30:41 pm
Up
Talented Doge
User
Offline Off
Code:
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
28
function loaduser(id)
     if USGN[id] > 0 then
          local file = io.open (dir..USGN[id]..".txt", "r")
          if file then
               local ranking_f,saycolor_f, taguse_f = file:read ("*l","*l","*n")
               ranking[id] = tonumber(ranking_f) or 0
               saycolor[id] = saycolor_f or "234205005"
               taguse[id] = tonumber(taguse_f) or 0
               saytag[id] = saytags[ranking[id]]
               file:close()
          else
               ranking[id] = 0
               saycolor[id] = "234205005"
               taguse[id] = 0
               saytag[id] = saytags[ranking[id]]
          end
     elseif player(id, "bot") then
          ranking[id] = 0
          saycolor[id] = "234205005"
          taguse[id] = 0
          saytag[id] = "(Bot)"
     else
          ranking[id] = 0
          saycolor[id] = "234205005"
          taguse[id] = 0
          saytag[id] = saytags[ranking[id]]
     end
end


I actually use the approach of saving each variable per line.
Talented Doge
17.11.16 04:22:27 pm
Up
muxarus
User
Offline Off
@user Talented Doge: thank you! I hope that this script will work!
IMG:http://steamsignature.com/status/german/76561198081961553.png
IMG:http://steamsignature.com/AddFriend.png
17.11.16 05:01:06 pm
Up
Yates
Reviewer
Offline Off
You should instead of writing things into a .txt file dump it into a Lua file and dofile it when you want to load data. You can then simply use the variables and overwrite the file to save.
17.11.16 08:23:02 pm
Up
muxarus
User
Offline Off
@user Yates: good idea, thx for reply! I will try to do it.
IMG:http://steamsignature.com/status/german/76561198081961553.png
IMG:http://steamsignature.com/AddFriend.png
To the start Previous 1 Next To the start