User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Array/Table save and load in LUA

  1. #1
    No Products Registered

    Join Date
    Sep 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array/Table save and load in LUA

    Does anyone know how I would be able to save-to-file a Multi-Dimensional Array in LUA?

    For example a rather large 2048x2048x10 array, all Integers. I "simply" want to be able to be able to save the array to a file like MMF does, and load it back into an array.

  2. #2
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    I think you will find this entire thread relevant to your situation (but it won't help you write array data to disk): http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=157991#Post1579 91

  3. #3
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    You could use an MMF array to read from the lua array, then save that MMF array to disk (and vice versa for loading it). But yes thats quite the nifty array you put together!

  4. #4
    No Products Registered

    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    wow i thought 500 x 500 x 10 was big lol.
    The way I do it is 'share' the values with an MMF array.
    Which means when you want to save, loop through each index and write into an mmf array and then save that. Then do the reverse when loading.
    Basically as Pixeltheif said.

    What I would like to see is the ability for lua to read/write directly to an MMF array, but doubt that will happen. Could make MMF unstable.

  5. #5
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    zellix shared some information with my on the subject. It might get added.

  6. #6
    Clicker Multimedia Fusion 2SWF Export Module

    Join Date
    Sep 2006
    Posts
    1,544
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    Aye, but running in MMF, you'll want to have VERY optimized code if you want this to take less than 5 minutes to write/read the array each time. I didn't notice how large your array was when you listed it- even in a binary array with the minimum size, 2048 * 2048 * 10 size of integers will requires 160 megabytes of memory for the application, and then 160 megabytes on the harddrive to write to

    Scratch what I said about using an array class- with something this horrendously large, you'll want to use the Binary Object of MMF2, and simply write the values to memory in the binary data rather than allocating such a ridiculously big array in MMF2 (which probably wouldn't even work for 160 megabytes)

    zellix shared some information with my on the subject. It might get added.
    after rereading the size, I think being able to export to a binary object instead of an array object might be more fitting here. Especially as your array.dll is already storing the data as an unformatted binary string anyway, isn't it? So it shouldn't be hard at all to export, hehe

  7. #7
    Clicker Multimedia Fusion 2
    Retriever2's Avatar
    Join Date
    Jun 2006
    Location
    United States
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    MMF arrays, if my information is correct, should store numbers as compactly as array.dll, or the binary object. What you don't get is flexibility over the width of the numeric type.

    Of course, an import/export for array.dll itself wouldn't be bad either.

  8. #8
    No Products Registered

    Join Date
    Sep 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    Ya, the size of my array might sound obscene, but I assure you it is for the server-side only, and the client side arrays will not be so massive (atleast if I do it correctly) then again, 160MB these days in memory isn't that much, especially if it is the game's foundation. I even toyed with a 4096x4096x10 array, but maybe later, because that is just huge ha.

    But, referring to passing the values to and from lua<->MMF I have done that, and with that size of an array, it is very very slow. I optimized it the best I could to my knowledge and it was still taking minutes, which would be unacceptable in most cases. I will try this array.dll out though, had no clue about it.

  9. #9
    No Products Registered

    Join Date
    Apr 2008
    Location
    Germany
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    Why don┤t write your own save/load function?
    Something like that:

    Code:
     
     function load(pfad)
     local text=""
     local char=""
     local n=1
     local temp={}
     
     file = io.open (pfad,"r") 
     if file==nil then 
    	return(nil) 
     end
     content = file:read("*a")
     file:close() 
    
     for i=1,string.len(content) do
      char=(string.char(string.byte(content,i) ))
      
      if char~="|" then 
        text=text..char
      else
       temp[n]=tonumber(text)
       n=n+1
       text=""
      end
     
     end
    
     return(temp)
    end 
    
    
    function save(pfad,Array)
     file = io.open (pfad,"w") 
    
     for i=1, table.getn(Array) do
      file:write(tostring(Array[i]).."|") 
     end
    
     file:close() 
    end

  10. #10
    No Products Registered

    Join Date
    Sep 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Array/Table save and load in LUA

    Well the existing MMF array saves and loads almost instantly, even at 160mb sizes. It also already has pre-sizing built in. Overall, if Retriever is able to link it in LUA like other MMF objects, it seems like the best choice. Looking at the structure of the MMF Array, it doesn't look as bad as I thought, and looks quite efficient actually. I do agree the downside to it is not being able to specify the value type, but that doesn't seem to be too big of a deal.

    But the save/load in LUA you posted is appreciated. It actually looks more straight-forward than the others I encountered and is good to have knowledge of.

Page 1 of 2 1 2 LastLast

Similar Threads

  1. LOAD/SAVE clone file in ARRAY FILE
    By daniele in forum Multimedia Fusion 2 - Technical Support
    Replies: 20
    Last Post: 24th July 2015, 01:47 AM
  2. Beta RC3- [BUG] Save & Load ini file to Array not functioning
    By Kisguri in forum Android Export Module Version 2.0
    Replies: 3
    Last Post: 16th January 2013, 08:44 PM
  3. Save/Load external Array
    By Fanotherpg in forum SWF/Flash Export Module Version 2.0
    Replies: 7
    Last Post: 6th May 2012, 11:31 AM
  4. Binary Array Save/Load File gets it Wrong
    By dragonguy in forum Multimedia Fusion 2 - Technical Support
    Replies: 24
    Last Post: 6th November 2008, 11:11 PM
  5. Array Save/ Load problems
    By RageO in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 23rd May 2007, 05:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •