2

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?

mpromonet
  • 11,326
  • 43
  • 62
  • 91
user2117118
  • 73
  • 1
  • 2
  • 10

1 Answers1

2

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()
mpromonet
  • 11,326
  • 43
  • 62
  • 91