2
votes

I am trying to write into a file and then read its contents the code I am using is:

file.remove("CRED.lua")
file.open("CRED.lua","w+")
temp = "PASS = "..pass
file.writeline(temp)
temp = "SSID = "..ssid
file.writeline(temp)
file.flush()
temp = nil
file.close()

It seems that the file is created but I when I do this:

dofile("CRED.lua")
print(PASS)
print(SSID)

I am getting both nil value.
Do you know why?

1
temp = "PASS = "..("%q"):format(pass) - Egor Skriptunoff

1 Answers

2
votes

In the CRED.lua file you have :

PASS = <password stored in pass variable>

As the <password stored in pass variable> variable is not set, execution will result setting PASS to nil.

You need to quote password and ssid, for instance using:

file.remove("CRED.lua")
file.open("CRED.lua","w+")
temp = "PASS = \""..pass.."\""
file.writeline(temp)
temp = "SSID = \""..ssid.."\""
file.writeline(temp)
file.flush()
temp = nil
file.close()