PDA

View Full Version : Startup variables



ddxfish
April 18th, 2010, 06:47 AM
I have been working with setting up a smarthome with an "away mode" and a "home mode". Away mode enables scheduled events like lighting, and home mode disables.

In my away mode macro, I have a scripting action to set a variable like so:
awaymode = "away"

The problem is that when I restart the computer, the variable is empty, and the webserver then does not display the variable.


What is the best way to keep variables through a restart?

Rob H
April 18th, 2010, 02:03 PM
See the help for the ptable Lua library

ddxfish
April 18th, 2010, 03:57 PM
Rob, thanks for the heads up. I have been reading and testing with ptables and have only been able to make a table, and not any variables inside it. Here is what Im using:

require('ptable')
myptable = ptable:New("myvariables")
myptable.setting1 = "Dark"


Which should set myptable.setting1 to Dark, but instead creates 2 entries in the new table "Close" and "Remove" both without variables.

Any advice?

Rob H
April 19th, 2010, 04:48 AM
You will indeed see that if you use the variable inspector or table.print(myptable)

However, if you type print(myptable.setting1) in the Lua console you should the correct value.

If you want to iterate over myptable then you need to use something like


for k,v in ptable:pairs(myptable) do
print(k, v)
end

ddxfish
April 19th, 2010, 05:00 AM
sweeeeeet its working now, thanks so much for the guidance rob, couldnt have done it without you.

Rob H
April 19th, 2010, 06:12 AM
That's what I'm here for :)

sirbooker
April 19th, 2010, 10:21 AM
you might want to do a search for (myvariables)
this script was created by a member called harleydude
i have been using it for a couple of years now and it works awsome for tracking variables and backing up and then restoring them.

Paul,

ddxfish
April 20th, 2010, 04:01 AM
I made a guide to what I just did.
http://www.etcwiki.org/wiki/Girder_persistent_varibles_using_ptables

Just in case anyone needs it.