de en es fr
Let the machine help
Light teasing, exhibition, BDSM, sissyfication, watersports... with sounds and pictures


Post new topic Reply to topic  [ 7 posts ] 
Author Message
 saving non volitile lists
PostPosted: Tue Feb 26, 2013 5:25 pm 
Offline
Shy
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


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Wed Feb 27, 2013 12:15 am 
Offline
Active member
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.


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Wed Feb 27, 2013 10:48 pm 
Offline
Site Admin
User avatar
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)


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Fri Sep 18, 2015 2:54 pm 
Offline
Newcomer
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> )


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Fri Dec 22, 2017 12:41 pm 
Offline
Site Admin
User avatar
Notice : this will be far easier with API 8 in a few weeks.


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Mon Jan 01, 2018 9:43 pm 
Offline
Site Admin
User avatar
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() )


Top
 Profile Send private message 
 
 Re: saving non volitile lists
PostPosted: Tue Jan 02, 2018 3:30 pm 
Offline
Veteran
User avatar
Thanks, very useful 8-)


Top
 Profile Send private message 
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Maroon Fusion theme created by Oxydo
Software, theme modifications, phpBB modification by Doti 2010 - 2020
This website uses session cookies only.