Announcement

Collapse
No announcement yet.

How to store data in a script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to store data in a script

    Suppose I have a script that needs to build a small data store that gets populated with additional data each time it's called. So the first time it's called, it stores "this string". The second time, it stores "that string". I want the script to know that there are now two strings, and what their values are. And so on. So the third time it's called with "another string", it should be able to write all 3 strings to the log. (This is just an example for clarity, not what I'm actually doing.)

    I tried declaring a public collection and adding to it each time the script is called, and the data is persistent as long as the calls happen fairly close together. But if the calls are separated by a minute or two, the script no longer has access to the data presented in the previous calls. So I guess some sort of garbage collection is being done. But how do I retain that data and prevent it from being destroyed?

    What's the right way to do this?

  • #2
    You can have a look at the global variables in HomeSeer. These values are stored as long HS3 is running. More info: http://homeseer.com/support/homeseer..._variables.htm

    If you want to save variables to be persistant even with a restart, I would have a look at either saving those values to a text file - or an ini file. More info: http://homeseer.com/support/homeseer...e_editing1.htm

    Wim
    -- Wim

    Plugins:RFXCOM, HSTouch Server, Squeezebox, BLGData, Restart, Jon00's Perfmon and Network monitor, WeatherXML, BLBackup, TenScripting, BC4, Pushover, PHLocation, JowiHue, Zwave, Sonos
    650 devices ---- 336 events ----- 40 scripts

    Comment


    • #3
      Yes, I know about globals and persistence across restarts. Globals won't work for this application because I need very fast access to the stored data structures. Pulling a global structure into my script will take too long.

      Looking at something like starting a separate processing thread that stays in memory, but I haven't done that before. I know it's possible, because I do something like that in my insteon_extdevsupport.vb script, I'm just not sure how to do it in a script that's not started by a plugin.

      Any examples of something like that would be greatly appreciated.

      Comment

      Working...
      X