Save In external .lua table
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Save In external .lua table

Started by Herodes, 05 June, 2004, 11:14:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Herodes

I was wondering how to save a table like the one that follows ...  :
---  logtables.dat 
LevelA = { 
LevelB1 = 3, 
LevelB2 = 4, 
LevelB3 = "string", 
LevelB4 = {}, 
LevelB5 = {},
LevelB6 = { [1] = "", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", },
LevelB7 = { [1] = "", [2] = "", [3] = "", [4] = "", [5] = "", [6] = "", [7] = "", [8] = "", [9] = "", }, 
	};
This table would be in a separate file So that the values are saved ...
Is there some way to Save them ?
If I just do
assert(dofile("whatever.dat"), "Ur .dat is missind ...")
then I can change the values but as soon the script is restarted ... u know the story .. (it doesn't save them )

So, I'd like if any one has the time to give me some pointers ...
I've been also looking in nErBoS User Logger and bonki's RecordBot
Still don't get it .. :S

[*edit*] Sry about the Title of the thread
"If its early in the morning for the most of u , for me its late at night .... very late ..." :P
The title should read :
Save table In external .dat

NightLitch

use this serialize, I got this from begining from Wombat.

-----------------------------------------------------------
function Serialize(tTable, sTableName, hFile, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(hFile, "hFile equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	write(hFile, sTab..sTableName.." = {\n" );
	for key, value in tTable do
		local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
		if(type(value) == "table") then
			Serialize(value, sKey, hFile, sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			write(hFile, sTab.."\t"..sKey.." = "..sValue);
		end
		write(hFile, ",\n");
	end
	write(hFile, sTab.."}");
end
-----------------------------------------------------------
function SaveFile(table , tablename, file)
	local hFile = openfile(file, "w");
	Serialize(table, tablename, hFile);
	closefile(hFile);
end
-----------------------------------------------------------
function LoadFile(file)
	assert(readfrom(file),file.." is not found.")
	dostring(read("*all"))
	readfrom()
end

Saving:

SaveFile(table, "tablename", filename)

In your case:

SaveFile(LevelA, "LevelA", filename)


loading:


LoadFile(filename)


put this in Main()

function Main()
    LoadFile(filename)
end

/NightLitch
//NL

((UKSN))shad_dow

lo NightLitch

can u explaine what it does ... in away a tables newbiee can understand :) thx

shad ?(
creator of Therapy-X? bot

plop

QuoteOriginally posted by ((UKSN))shad_dow
lo NightLitch

can u explaine what it does ... in away a tables newbiee can understand :) thx

shad ?(
it's hard 2 explain what goes on if you don't understand tables fully.
but the moment you understand them you'll see that you understands whats going on in this function.
but it isn't needed 2 understand whats going on 2 be able 2 use this, aslong as you know how 2 trigger it 2 save things.
and nightlitch explained that perfectly.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

SMF spam blocked by CleanTalk