English Load function !

11 replies
Goto Page
To the start Previous 1 Next To the start
27.04.18 11:23:40 pm
Up
minos
User
Offline Off
Hello guys i have made a command with save and load function and when i write !password <code> it saves perfectly but when I want to load my data with !login command it doesn't work !
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
elseif string.sub(txt,1,7)=="!login " then
USGN[id] = string.sub(txt,8,13)
password[id] = string.sub(txt,14,string.len(txt))
parse(USGN[id].." "..password[id])
  local file = io.open ("sys/lua/goRANK/"..USGN[id]..".txt","r")
          if file then
               local pid = file:read("*n")
                  password[id] = pid
               file:close ()
               msg2(id,"\169255255255Profile successfully loaded.")
  local file2 = io.open ("sys/lua/goRANK/"..USGN[id].."(2).txt","r")
          elseif file2 then 
                local nid = file2:read("*n")
                 nickteam[id] = nid
                 file2:close ()
                 else
                  msg2(id,"failed")
          end
return 1
l
28.04.18 01:15:59 am
Up
Cebra
User
Offline Off
maybe you look for something like this:
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
elseif string.sub(txt,1,7)=="!login " then
     USGN[id] = string.sub(txt,8,13)
     password[id] = string.sub(txt,14,string.len(txt))

     local file = io.open ("sys/lua/goRANK/"..USGN[id]..".txt","r")
     if file then
          local pid = file:read("*n")
          file:close ()
          if pid==password[id] then
               
               local file2 = io.open ("sys/lua/goRANK/"..USGN[id].."(2).txt","r")
               if file2 then
                    nickteam[id] = file2:read("*n")
                    file2:close()
                    msg2(id,"\169255255255Profile successfully loaded.")
               end
          else
               msg2(id,"failed")
          end
return 1
loading...
28.04.18 01:51:11 am
Up
minos
User
Offline Off
@user Cebra: it didn't work ,but thanks for trying.
l
28.04.18 11:58:49 am
Up
Cebra
User
Offline Off
maybe you can post the whole code?
Then we/i can help you better
loading...
28.04.18 06:34:01 pm
Up
minos
User
Offline Off
@user Cebra: Here is the !password part :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
elseif string.sub(txt,1,10)=="!password " then
local pid = string.sub(txt,11,string.len(txt)) 
password[id] = pid
parse(pid)
          local file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","w")
          local pid = password[id]
          file:write (pid)
          file:close ()
            local file2 = io.open("sys/lua/goRANK/"..player(id,"usgn").."(2).txt","w")
            local nid = nickteam[id] 
            file2:write(nid)
            file2:close()
            
            msg2(id,"Saved")
            return 1
            else
            msg2(id,"Failed")
l
29.04.18 11:58:14 am
Up
Cebra
User
Offline Off
Code:
1
parse(USGN[id].." "..password[id])

and
Code:
1
parse(pid)

do nothing.
and post the error-message from the console, it helps you to find the bug
loading...
29.04.18 05:33:35 pm
Up
minos
User
Offline Off
@user Cebra: There is no bugs only that load function doesn't read save function lines :v
l
29.04.18 08:18:57 pm
Up
Cebra
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
29
30
31
32
33
34
35
36
37
38
function initArray(m,v)
     local array={}
     for i=1, m do
          array[i]=v
     end
     return array
end

password = initArray(32,null)
nickteam = initArray(32,null)

addhook("say","_say")
function _say(id,txt)
     if string.sub(txt,1,10)=="!password " then
          password[id] = string.sub(txt,11,string.len(txt))
          local file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","w")
          file:write(password[id].."\n")
          file:write(nickteam[id])
          file:close ()
          msg2(id,"Saved")
          return 1
     elseif string.sub(txt,1,7)=="!login " then
          password[id] = string.sub(txt,8,string.len(txt))
          file = io.open ("sys/lua/goRANK/"..player(id,"usgn")..".txt","r")
          if file~=null then
               savedPW = file:read("*line")
               savedNID = file:read("*n")
               file:close()
               if password[id]==savedPW then
                    nickteam[id] = savedNID
                    msg2(id,"\169255255255Profile successfully loaded.")
               else
                    msg2(id,"failed, pw incorrect")
               end
          end
          return 1
     end
end
loading...
30.04.18 02:40:41 am
Up
Waldin
User
Offline Off
read cs2d lua cmd parse please, it executes console commands, that doesnt help you with writing/reading passwords.

also remember that Jesus loves you
user Waldin (2014) has written:
can be create 3D option for tiles on 3D
user DC (2014) has written:
@user Waldin: This is a 2D game. there are no 3D tiles.
changelog (2017) has written:
ADDED Experimental 3D rendering mode
01.05.18 12:18:33 am
Up
minos
User
Offline Off
user Cebra thank you for your costly time i have replaced it with an other way
l
01.05.18 02:47:02 pm
Up
VaiN
User
Offline Off
If you are planning to save/load player data, you could make things easier on yourself by just saving it as a table.
check out file cs2d [SALT] Save and Load Tables (12)

Also, here I gave an example of saving/loading player data.

The use of string.sub() for commands just makes my head hurt. If you plan on making something more advanced you may want to consider creating a command processor. Here's a basic example of one.

Hope that helps.
01.05.18 05:55:43 pm
Up
minos
User
Offline Off
user VaiN has written:
If you are planning to save/load player data, you could make things easier on yourself by just saving it as a table.
check out file cs2d [SALT] Save and Load Tables (12)

Also, here I gave an example of saving/loading player data.

The use of string.sub() for commands just makes my head hurt. If you plan on making something more advanced you may want to consider creating a command processor. Here's a basic example of one.

Hope that helps.

Thank you mate your save lua is quite good but i don't know how to make it as a command to save only the user command player.
l
To the start Previous 1 Next To the start