AndyGFX Posted June 1, 2010 Posted June 1, 2010 File Name:Save data to lua syntax (as text/compressed) File Submitter: AndyGFX File Submitted: 01 Jun 2010 File Updated: 01 Jun 2010 File Category: Lua Scripts I wrote TStoreData.lua class for simple save data to standard lua format, which is simple to read back to script (described here: HowTo using LUA script as data file) Example: Save Data require ("class/TStoreData") test_data = { pos = {0,1,2}, name = "player1", other = { items = {"item1","item2","item3"}, subitems = {"A","B"}, data = { x = 0, y = 1, z= 2}, tree = { leaf1 = "l1", leaf2 = "2", leaf3 = { leaf31 = "31", leaf32 = "32"}, used = true } } } DataSaver = TStoreData:New() -- save uncompressed data DataSaver:Save("result.lua",false,test_data) -- save compressed data -- DataSaver:Save("result.lua",true,test_data) Output: return { ["other"] = { ["items"] = { [1] = "item1"; [2] = "item2"; [3] = "item3"; }; ["subitems"] = { [1] = "A"; [2] = "B"; }; ["data"] = { ["y"] = 1; ["x"] = 0; ["z"] = 2; }; ["tree"] = { ["used"] = true; ["leaf3"] = { ["leaf32"] = "32"; ["leaf31"] = "31"; }; ["leaf1"] = "l1"; ["leaf2"] = "2"; }; }; ["name"] = "player1"; ["pos"] = { [1] = 0; [2] = 1; [3] = 2; }; } Example#1: Load Data GameData = dofile("result.lua") print(GameData.pos[1],GameData.pos[2],GameData.pos[3]) print(GameData.name) print(GameData.other.items[1]) print(GameData.other.items[2]) print(GameData.other.items[3]) Example#2: Load Data require ("class/TStoreData") LoadData = TStoreData:New() GameData = LoadData:Load("result.lua") print(GameData.pos[1],GameData.pos[2],GameData.pos[3]) print(GameData.name) print(GameData.other.items[1]) print(GameData.other.items[2]) print(GameData.other.items[3]) Note: Saved format looks little bit different, but this saved format is only other lua syntax. Work same like before. Click here to download this file 2 Quote [HW] C2D Q6600, 4GB RAM, NV8800GTX, Vista Ultimate x64 [sW] Blide Plus, BlitzMax, Delphi, C++, 3DWS 5.53, Leadwerks 2.xx
Pancakes Posted June 1, 2010 Posted June 1, 2010 I will endeavor to understand this Andy. Quote Core I5 2.67 / 16GB RAM / GTX 670 Zbrush/ Blender / Photoshop CS6 / Renoise / Genetica / Leadwerks 3
gordonramp Posted June 3, 2010 Posted June 3, 2010 I will be making a video tutorial for this. Looking forward to that Quote AMD Athlon x2 7750 2.7ghz, 6gb ddr2 ram, Galaxy9800GT 1gig ddr2 video card, Windows 7,64.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.