scargill wrote:If you create a file using a serial terminal you can easily make default values for variables on power up. But while using a variable in a Lua programming legs say to control a light how do you make that non volatile so it stays put through power cycling???
The only way is to write variables to a file and load these on init. I don't think there is any other way in Lua.
I need 2 routines - one to update or add a line to a lua file if not there - the other to read a value.
So lets say the lua file has the following in it
a=1
b=2
Open the file - that's easy - read ta line at a time - that's easy - and that's where I went wrong.
a="pin=9"
item,value=string.gmatch(a, "(%w+)=(%w+)")
print(item)
print(value)
Doesn't work - bear in mind I'm rubbish at Lua and I don't want to add a library - need the simplest route... Why doesn't the above split the line into "a" and "9"
??
So what I'm after is to end up with 2 short functions..
x=readvar("a")
updatevar("a","45)
Anyone feeling ambitious - remember it needs to be short and fast?
And before anyone says you should make a temporary file - we don't have file.rename !!
I think someone needs to put in a request...ZERODAY are you looking in?
item,value=string.match(a, "(%w+)=(%w+)")
instead of string.gmatch.