I want when I write this INI file that the Table looks like this:
TABLE = {"[NAME1]","[NAME2]"}
how do I change this so it writes like above
and Not:
TABLE = {"[NAME1]"}
TABLE = {"[NAME2]"}
with this:
for key,nick in BadISP do
sIni = sIni .. "\r\nBadISP = {\""..nick.."\"}"
end
pls help me / NightLitch
write(handle, tablename.." = {\n" )
for key, value in table do
write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
end
write(handle, "}");
if this is about you nick rule its gonna be added to the Logger ;). And it works already it only need some rewriting.
Ok Chilla am way off now...
How would this look like I have just pasted and ...
plz correct...
function doSaveInifile(curUser)
local sIni = ""
sIni = sIni .. "\r\n--[ BotName ]--"
sIni = sIni .. "\r\nBot = \""..Bot.."\""
sIni = sIni .. "\r\n--[ USER LOG NAME/IP ]--"
sIni = sIni .. "\r\nUSERLOG = \""..USERLOG.."\" --// enable/disable"
sIni = sIni .. "\r\n--[ Bad Network ISP's ]--"
sIni = sIni .. "\r\nISPCHECK = \""..ISPCHECK.."\" --// enable/disable"
for key,nick in BadISP do
sIni = sIni .. "\r\nBadISP = {\""..nick.."\"}"
end
sIni = sIni .. "\r\n"
-- open and write to file
writeto(sIniFile)
write(sIni)
writeto()
curUser:SendData("$To: "..curUser.sName.." From: "..Bot.." $***Settings saved to file")
dofile("IP-Boter.ini")
end
/NightLitch
And No this is for my IP-BOTER...
Just doing this to learn some more...
But have got stuck...
so need your or someone else's help...
if you only want to save one tablke containg only a key and a value where value is not a table again this simple thing should do.
table = YOURTABLE
tablename = "TABLENAME"
YOURFILE = "PATHANDFILE"
local handle = openfile(YOURFILE, "w")
write(handle, tablename.." = {\n" )
for key, value in table do
write(handle, "\t"..format("[%q]",key).." = "..value..",\n")
end
write(handle, "}");
for advanced serialisation use this from RabidWombat..
damn where is he miss him a lot, he was the best...
function WriteFile(table,tablename,file)
local handle = openfile(file,"w")
Serialize(table,tablename,handle)
closefile(handle)
end
----------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
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
whats the point in letting others write your script ?
youll never know what goes on in it and youll never learn
Wanna now the truth so I have almost fixed it myself...
Have one problem doo...
local l = {}
for k,v in BadISP do
tinsert(l,k)
end
sort(l)
local s = "BadISP = {"
for i=1, l.n do
s = s .. "\[\"" .. l[i] .. "\"\] = \"" .. tostring(BadISP[l[i]]) .. "\""
end
local s = s.."}"
sIni = sIni .. (s)
I only want it to write the name not number...
No need to help me... I have solved it myself again...
But I thank you all for the help...
It's funny how the head can stand still a minute or two :-p and then I just get it working...
ThX Guys / NightLitch