SexScripts : saving non volitile lists - https://ss.deviatenow.com:443/viewtopic.php?f=4&t=293 Page 1 of 1

saving non volitile lists

brian_willson [ Tue Feb 26, 2013 5:25 pm ]

So we can save variables of type into float or string, but if I wish to save a list of tasks to do for example. Todays assignments.
I would also want to remove items at various points in the list, I could save multiple lists if I wanted to store parameters to each list item



How would this be done

Re: saving non volitile lists

0385 [ Wed Feb 27, 2013 12:15 am ]

well, there is
Quote:
save(String key, * value)
Saves something (String, Integer,Float, Boolean) in datafile. See loadBoolean(), loadInteger(), etc. - See more at: viewtopic.php?f=4&t=2#sthash.9tNLsE0e.dpuf

Perhaps you can save things to custom files and read from/write to there, check the documentation and the groovy help pages.

Re: saving non volitile lists

doti [ Wed Feb 27, 2013 10:48 pm ]

The best solution may be to convert a list of strings (or an array of strings) to a simple string, then save it.

Creating the list, saving it :
Code:
def l = ["This"]
l += ["is"]
l += ["pink"]
save("test.list", l.join("_"))


Back :
Code:
def l = loadString("test.list").tokenize("_");


(edit: deprecated, see below)

Re: saving non volitile lists

wodahs [ Fri Sep 18, 2015 2:54 pm ]

I have a parser written to solve this problem.

Code:
def loadMDA
loadMDA = { loadString, index = 0, depth = 0 ->
   def i
   def arr = []
   def string = ""
   
   if (loadString != null)
   {
      for (i = index; i < loadString.size(); i++)
      {
         if (loadString[i] == "[")
         {
            depth++
            i++

            def (tmpArr, i_new) = loadMDA(loadString, i, depth)

            depth--

            if (depth == 0)
               return tmpArr
            
            arr.add( tmpArr )
            i = i_new
         }
         else
         {
            if (loadString[i] == "]")
            {
               if (string != "")
                  arr.add(string)
               string = ""
               
               return [arr, i]
            }
            else if (loadString[i] == ",")
            {
               if (string != "")
                  arr.add(string)
               string = ""
               i++
            }
            else
            {
               string += loadString[i]
            }
         }
      }
      return [arr, i]
   }
}


To parse the array
Code:
def array = loadMDA( <text> )

Re: saving non volitile lists

doti [ Fri Dec 22, 2017 12:41 pm ]

Notice : this will be far easier with API 8 in a few weeks.

Re: saving non volitile lists

doti [ Mon Jan 01, 2018 9:43 pm ]

With the API 8 from today, you can save and load a while list of data.

from the example above :

Creating the list, saving it :
Code:
def l = ["This"]
l += ["is"]
l += ["pink"]
save("test.list", l)

Or:
Code:
save("test.list", ["This", "is", "pink"])


Back :
Code:
def l = load("test.list")
show(l[0] + l[1] + l[2])


(works also with send() / receive() )

Re: saving non volitile lists

arthurb [ Tue Jan 02, 2018 3:30 pm ]

Thanks, very useful 8-)

Page 1 of 1 All times are UTC + 1 hour [ DST ]
https://ss.deviatenow.com:443/
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010, 2011