Need some help here...
 

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

Need some help here...

Started by NightLitch, 27 October, 2003, 18:23:12

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

NightLitch

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
//NL

c h i l l a

#1
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.

NightLitch

#2
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
//NL

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...
//NL

c h i l l a

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

tezlo

whats the point in letting others write your script ?
youll never know what goes on in it and youll never learn

NightLitch

Wanna now the truth so I have almost fixed it myself...
//NL

NightLitch

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...
//NL

NightLitch

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
//NL

SMF spam blocked by CleanTalk